﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
//???????
int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
	for (int i = 0; i < numsSize - 1; ++i) {
		for (int j = i + 1; j < numsSize; ++j) {
			if (nums[i] + nums[j] == target) {
				int* res = malloc(sizeof(int) * 2);
				res[0] = i, res[1] = j;
				*returnSize = 2;
				return res;
			}
		}
	}
	*returnSize = 0;
	return NULL;
}
//???
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* plusOne(int* digits, int digitsSize, int* returnSize)
{
	int i = 0;
	int k = 0;
	int sum = 0;
	for (i = 0; i < digitsSize; i++)
	{
		if (digits[i] == 9)
		{
			k = 1;
		}
		else
		{
			k = 0;
		}
		sum += k;
	}
	if (sum == digitsSize)
	{
		int* ret = (int*)malloc(sizeof(int) * (digitsSize + 1));
		for (i = 0; i < digitsSize + 1; i++)
		{
			if (i == 0)
			{
				*(ret + i) = 1;
			}
			else
			{
				*(ret + i) = 0;
			}
		}

		*returnSize = digitsSize + 1;
		return ret;
	}
	if (sum < digitsSize)
	{
		for (i = digitsSize - 1; i >= 0; i--)
		{
			if (digits[i] == 9)
			{
				digits[i] = 0;
			}
			else
			{
				digits[i] = digits[i] + 1;
				break;
			}

		}
		*returnSize = digitsSize;
		return digits;
	}
	return 1;
}
//????????
bool detectCapitalUse(char* word)
{
	int k = 0;
	int count = 0;
	char* middle = word;
	while (*word != '\0')
	{
		count++;
		word++;
	}
	word = middle;
	while (*word != '\0')
	{
		if (*word >= 'A' && *word <= 'Z')
		{
			k++;
		}
		word++;
	}
	word = middle;
	if (k == count)
		return true;
	else if (k == 0)
		return true;
	else if ((*word >= 'A') && (*word <= 'Z') && (k == 1))
		return true;
	else
		return false;
}
//???????????
int countSegments(char* s)
{
	char* start = s;
	int count = 0;
	while (*start != '\0')
	{
		char* end = start;
		while (*end == ' ' && *end != '\0')
			end++;
		if (*end == '\0')
			return count;
		count++;
		while (*end != ' ' && *end != '\0')
			end++;
		start = end;
	}
	return count;
}
//?????
void moveZeroes(int* nums, int numsSize)
{
	int* start = nums;
	while (start != nums + (numsSize - 1))
	{
		while (*start != 0 && start != (nums + numsSize - 1))
			start++;
		if (start == nums + (numsSize - 1))
		{
			return;
		}
		int* end = start;
		while (*end == 0 && end != nums + (numsSize - 1))
			end++;
		int tem = *start;
		*start = *end;
		*end = tem;
		start++;
	}
}
//???????
int hammingWeight(int n)
{
	int count = 0;
	while (n != 0)
	{
		if ((n & 1) == 1)
		{
			count++;
		}
		n = n >> 1;
	}
	return count;
}
//????????
void reverse(char* left, char* right)
{
	while (left < right)
	{
		char* temp = *left;
		*left = *right;
		*right = temp;
		left++;
		right--;
	}
}
void reverseString(char* s, int sSize)
{
	reverse(s, s + (sSize - 1));
}
//?????????????
int intcompare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
int singleNumber(int* nums, int numsSize)
{
	int i = 0;
	int sz = numsSize - 1;
	qsort(nums, numsSize, sizeof(int), intcompare);
	if (numsSize == 1)
	{
		return nums[0];
	}
	if (nums[0] != nums[1])
	{
		return nums[0];
	}
	else if (nums[sz] != nums[sz - 1])
	{
		return nums[sz];
	}
	else
	{
		for (i = 1; i < numsSize - 1; i++)
		{
			if (nums[i] == nums[i - 1] || nums[i] == nums[i + 1])
			{
				continue;
			}
			else
			{
				return nums[i];
			}
		}
	}
	return 0;
}
//4????
bool isPowerOfFour(int n)
{
	if (n == -pow(2, 31))
	{
		return false;
	}
	int x = 0;
	int f = 0;
	for (x = 0; x < 31; x++)
	{
		f = pow(4, x);
		if (f >= (-(int)pow(2, 31)) && f <= ((int)pow(2, 31) - 1))
		{
			if (n == f)
			{
				return true;
			}
		}
	}
	return false;
}
//???????????????
bool isPerfectSquare(int num)
{
	int i = 1;
	for (i = 1; i <= 46340; i++)
	{
		if (num == (i * i))
			return true;
	}
	return false;
}
//????????????????
void reverse(char* left, char* right)
{
	while (left < right)
	{
		char a = *left;
		*left = *right;
		*right = a;
		left++;
		right--;
	}
}
char* reverseWords(char* s)
{
	char* ret = s;
	char* start = s;
	while (*start != '\0')
	{
		char* end = start;
		while (*end == ' ' && *end != '\0')
			end++;
		start = end;
		end = start;
		while (*end != ' ' && *end != '\0')
			end++;
		reverse(start, end - 1);
		start = end;
	}
	return ret;
}
//????????????????
void reverse(char* left, char* right)
{
	char a = *left;
	*left = *right;
	*right = a;
}
char* reverseVowels(char* s)
{
	char* ret = s;
	char* start = ret;
	char* end = s + strlen(ret) - 1;
	while (start < end)
	{
		while (*start != 'a' && *start != 'e' && *start != 'i' && *start != 'o' && *start != 'u' && *start != 'A' && *start != 'E' && *start != 'I' && *start != 'O' && *start != 'U' && *start != '\0')
			start++;
		while (*end != 'a' && *end != 'e' && *end != 'i' && *end != 'o' && *end != 'u' && *end != 'A' && *end != 'E' && *end != 'I' && *end != 'O' && *end != 'U' && end != ret)
			end--;
		if (start < end)
		{
			reverse(start, end);
		}
		start++;
		end--;
	}
	return ret;
}
//????
int charcompare(const void* a, const void* b)
{
	return (*(char*)a - *(char*)b);
}
int charcompare1(const void* a, const void* b)
{
	return (*(char*)a - *(char*)b);
}
int findTheDifference(char* s, char* t)
{
	qsort(s, strlen(s), sizeof(char), charcompare);
	qsort(t, strlen(t), sizeof(char), charcompare1);
	while (*s != '\0' && *t != '\0')
	{
		if (*s != *t)
			return *t;
		s++;
		t++;
	}
	return *t;

}
//?????????????????
int panduan(char* start, char* end, char* s)
{
	char* f = s;
	while (f < start)
	{
		if (*f == *start)
			return 1;
		f++;
	}
	while (start < end)
	{
		if (*start == *end)
			return 1;
		end--;
	}
	return 0;
}
int firstUniqChar(char* s)
{
	if (strlen(s) == 1)
		return 0;
	int k = 0;
	int i = 0;
	char* end = s + strlen(s) - 1;
	char* f = s;
	char* start = s;
	while (start <= end)
	{
		int ret = panduan(start, end, s);
		if (ret == 1)
		{
			if (start != end)
				start++;
			else
				break;
		}
		else
		{
			while (f != start)
			{
				f++;
				k++;
			}
			return k;
		}
	}
	return -1;
}
//????????
bool rotateString(char* s, char* goal)
{
	int i = 0;
	int j = 0;
	int f = strlen(s);
	int sz = strlen(s) - 1;
	for (i = 0; i < f; i++)
	{
		char a = s[0];
		for (j = 0; j < sz; j++)
		{
			s[j] = s[j + 1];
		}
		s[sz] = a;
		if (strcmp(s, goal) == 0)
			return true;
	}
	return false;
}
//????????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* addToArrayForm(int* num, int numSize, int k, int* returnSize)
{
	int p = 0;
	int i = numSize - 1;
	int j = 0;
	int h = 0;
	if (numSize == 1)
	{
		num[0] = num[0] + k;
	}
	else
	{
		for (i = numSize - 1; i >= 0; i--)
		{
			if (i == 0)
			{
				num[0] = num[i] + k;
				break;
			}
			j = k % 10;
			num[i] = num[i] + j;
			k /= 10;
			if (k == 0)
				break;
		}
	}
	for (i = numSize - 1; i > 0; i--)
	{
		if (num[i] > 9)
		{
			num[i] = num[i] % 10;
			num[i - 1] = num[i - 1] + 1;
		}
	}
	if (num[0] > 9)
	{
		p = num[0];
		while (p)
		{
			p /= 10;
			h++;
		}
		int* arr = (int*)malloc(sizeof(int) * (numSize + h - 1));
		if (arr == NULL)
		{
			return NULL;
		}
		for (j = h - 1; j >= 0; j--)
		{
			*(arr + j) = num[0] % 10;
			num[0] /= 10;
			if (num[0] == 0)
				break;
		}
		j = h;
		for (i = 1; i < numSize; i++)
		{
			*(arr + j) = num[i];
			j++;
		}
		*returnSize = numSize + h - 1;
		return arr;
	}
	else
	{
		int* arr = (int*)malloc(sizeof(int) * (numSize));
		if (arr == NULL)
		{
			return NULL;
		}
		for (i = 0; i < numSize; i++)
		{
			*(arr + i) = num[i];
		}
		*returnSize = numSize;
		return arr;
	}
}
//?????????????
int intcompare(const void* a, const void* b)
{
	return (*(int*)(b)-*(int*)(a));
}
int maximumProduct(int* nums, int numsSize)
{
	qsort(nums, numsSize, sizeof(int), intcompare);
	int sz = numsSize - 1;
	int a = nums[0];
	int b = nums[1];
	int c = nums[2];
	if (numsSize == 3)
		return a * b * c;
	if (numsSize == 4)
	{
		if (a < 0)
			return a * b * c;
		if (a > 0 && b > 0 && c > 0)
			return a * b * c;
		if (a > 0 && b > 0)
			return a * nums[numsSize - 1] * nums[numsSize - 2];
		if (a > 0 && b <= 0)
			return a * nums[numsSize - 1] * nums[numsSize - 2];
		return a * b * c;
	}
	if (numsSize == 5)
	{
		if (a < 0)
			return a * b * c;
		if ((nums[numsSize - 1] * nums[numsSize - 2]) >= (a * b))
			return a * nums[numsSize - 1] * nums[numsSize - 2];
		if (a > 0 && b > 0 && c <= 0)
			return a * nums[numsSize - 1] * nums[numsSize - 2];
		return a * b * c;
	}
	if (numsSize >= 6)
	{
		if (a < 0)
			return a * b * c;
		if ((nums[numsSize - 1] * nums[numsSize - 2]) >= (a * b))
			return a * nums[numsSize - 1] * nums[numsSize - 2];
		if (a > 0 && b > 0 && c <= 0)
			return a * nums[numsSize - 1] * nums[numsSize - 2];
		if ((nums[numsSize - 1] * nums[numsSize - 2]) >= (c * b))
			return a * nums[numsSize - 1] * nums[numsSize - 2];
		return a * b * c;
	}
	return a * b * c;
}
//????????
int fib(int n)
{
	if (n == 0)
		return 0;
	int a = 1;
	int b = 1;
	int c = 1;
	while (n >= 3)
	{
		c = a + b;
		a = b;
		b = c;
		n--;
	}
	return c;
}
//????????????
void fun(char* ret)
{
	char* str = ret;
	int i = 0;
	int j = 0;
	for (i = 0; ret[i] != '\0'; i++)
	{
		if (ret[i] != ' ')
		{
			str[j] = ret[i];
			j++;
		}
		if (ret[i] == ' ' && ret[i - 1] != ' ')
		{
			str[j] = ret[i];
			j++;
		}
	}
	str[j] = '\0';
	ret = str;
}
void reverse(char* left, char* right)
{
	while (left < right)
	{
		char a = *left;
		*left = *right;
		*right = a;
		left++;
		right--;
	}
}
char* reverseMessage(char* message)
{
	if (strlen(message) == 2 && message[0] == ' ' && message[1] == '1')
	{
		char* ret1 = message + 1;
		return ret1;
	}
	int k = 0;
	char* ret = message;
	char* left = message;
	int sz = strlen(message);
	char* right = message + strlen(message) - 1;
	int i = 0;
	int j = 0;
	for (i = 0; i < sz; i++)
	{
		if (message[i] != ' ')
			break;
		else
		{
			for (j = i; j < sz - 1; j++)
			{
				message[j] = message[j + 1];
			}
			i--;
			sz = sz - 1;
		}
	}
	reverse(left, right);
	char* start = message;
	while (*start != '\0')
	{
		char* end = start;
		while (*end == ' ' && *end != '\0')
			end++;
		start = end;
		end = start;
		while (*end != ' ' && *end != '\0')
			end++;
		reverse(start, end - 1);
		if (*end != '\0')
			end++;
		start = end;
	}
	start = message;
	while (*start == ' ')
	{
		start++;
		k++;
	}
	ret = message + k;
	fun(ret);
	return ret;
}
//?????????
bool isValid(char* s)
{
	if (s == NULL)
		return false;
	char* p = (char*)malloc(sizeof(char) * (strlen(s) + 1));
	int top = 0;
	int i = 0;
	for (i = 0; s[i] != '\0'; i++)
	{
		if (s[i] == '(' || s[i] == '[' || s[i] == '{')
			p[++top] = s[i];
		else if ((p[top] == '(' && s[i] == ')') || (p[top] == '[' && s[i] == ']') || (p[top] == '{' && s[i] == '}'))
			top--;
		else
			return false;
	}
	if (p != NULL)
	{
		free(p);
		p = NULL;
	}
	if (top == 0)
		return true;
	return false;
}
//?????????
int intcompare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
int missingNumber(int* nums, int numsSize)
{
	qsort(nums, numsSize, sizeof(int), intcompare);
	int* p = (int*)malloc(sizeof(int) * (numsSize + 1));
	int i = 0;
	for (i = 0; i <= numsSize; i++)
	{
		*(p + i) = i;
	}
	for (i = 0; i < numsSize; i++)
	{
		if (nums[i] != *(p + i))
			return *(p + i);
	}
	return *(p + i);
}
//?????
int climbStairs(int n)
{
	if (n == 2)
		return n;
	if (n == 3)
		return n;
	int a = 2;
	int b = 3;
	int c = 1;
	while (n > 3)
	{
		c = a + b;
		a = b;
		b = c;
		n--;
	}
	return c;
}
//??????
int addDigits(int num)
{
	int sum = 0;
	int ret = 0;
	while (num)
	{
		sum += (num % 10);
		num /= 10;
	}
	while (sum > 9)
	{
		ret = sum;
		sum = 0;
		while (ret)
		{
			sum += (ret % 10);
			ret /= 10;
		}
	}
	return sum;
}
//2????
bool isPowerOfTwo(int n)
{
	int x = 0;
	int f = 0;
	if (n == -2147483648)
	{
		return false;
	}
	for (x = 0; x < 32; x++)
	{
		f = pow(2, x);
		if (f <= (pow(2, 31) - 1))
		{
			if (n == f)
			{
				return true;
				break;
			}
		}

	}

	return false;
}
//x???????
#include <stdio.h>
#include <math.h>
int mySqrt(int x)
{
	return (int)sqrt(x);
}
//3????
bool isPowerOfThree(int n)
{
	int i = 0;
	if (n == -(int)pow(2, 31))
	{
		return false;
	}
	for (i = 0; i < 32; i++)
	{
		if (pow(3, i) <= (pow(2, 31) - 1) && (pow(3, i) >= -(int)pow(2, 31)))
		{
			if (n == pow(3, i))
			{
				return true;
			}
		}
	}
	return false;
}
//??????
int removeElement(int* nums, int numsSize, int val)
{
	int i = 0;
	int j = 0;
	if (numsSize == 1)
	{
		if (nums[0] == val)
		{
			numsSize--;
		}

	}
	else
	{
		for (i = 0; i < numsSize; i++)
		{
			if (nums[i] == val)
			{
				for (j = i; j < numsSize - 1; j++)
				{
					nums[j] = nums[j + 1];
				}
				numsSize--;
				i--;
			}

		}
	}
	return numsSize;
}
//??????????????
int last_word(char* left, char* right)
{
	int count = 0;
	while (left <= right)
	{
		if (*left != '\0')
		{
			count++;
		}
		left++;
	}
	return count;
}
int lengthOfLastWord(char* s)
{
	char* start = s;
	char* end = start;
	while (*end != '\0')
	{
		end++;
	}
	end--;
	while (*end == ' ')
	{
		end--;
	}
	start = end;
	while (*start != ' ')
	{
		if (start == s)
		{
			break;
		}
		start--;
	}
	if (start == s && *start != ' ')
	{
		int ret = last_word(start, end);
		return ret;
	}
	else
	{
		int ret = last_word(start + 1, end);
		return ret;
	}
}
//???????????????
int compare(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n)
{
	int i = 0;
	for (i = 0; i < nums1Size; i++)
	{
		if (nums1[i] == 0)
		{
			if (i == m)
			{
				break;
			}

		}
	}
	memcpy(nums1 + i, nums2, sizeof(int) * n);
	qsort(nums1, nums1Size, sizeof(int), compare);
}
//???????????
int searchInsert(int* nums, int numsSize, int target)
{
	int i = 0;
	for (i = 0; i < numsSize; i++)
	{
		if (target <= nums[i])
		{
			break;
		}
	}
	return i;
}
//?????????????????????
int strStr(char* haystack, char* needle)
{
	int i = 0;
	char* ret = NULL;
	ret = strstr(haystack, needle);
	if (ret == NULL)
	{
		return -1;
	}
	else
	{
		for (i = 0; i < strlen(haystack); i++)
		{
			if (strcmp(haystack + i, ret) == 0)
			{
				break;
			}
		}
		return i;
	}

}
//?????????????????
int removeDuplicates(int* nums, int numsSize)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < numsSize - 1; i++)
	{
		if (nums[i] == nums[i + 1])
		{
			int sz = i + 1;
			memmove(nums + i, nums + sz, sizeof(int) * (numsSize - sz));
			numsSize--;
			i--;
		}
	}
	return numsSize;
}
//???????????
int intcmpare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
bool containsDuplicate(int* nums, int numsSize)
{
	qsort(nums, numsSize, sizeof(int), intcmpare);
	int i = 0;
	for (i = 0; i < numsSize - 1; i++)
	{
		if (nums[i] == nums[i + 1])
		{
			return true;
		}
	}
	return false;
}
//?????????
int sum(int num1, int num2) {
	return num1 + num2;
}
//??????
char charcompare(char* a, char* b)
{
	return strcmp(a, b);
}
bool canConstruct(char* ransomNote, char* magazine)
{
	qsort(ransomNote, strlen(ransomNote), sizeof(char), charcompare);
	qsort(magazine, strlen(magazine), sizeof(char), charcompare);
	char* p = (char*)malloc(sizeof(char) * strlen(ransomNote));
	if (p == NULL)
	{
		return false;
	}
	int top = 0;
	int i = 0;
	for (i = 0; ransomNote[i] != '\0'; i++)
	{
		p[top] = ransomNote[i];
		top++;
	}
	for (i = strlen(magazine) - 1; i >= 0; i--)
	{
		if (p[top - 1] == magazine[i])
		{
			top--;
		}
		if (top == 0)
			return true;

	}
	if (top == 0)
		return true;
	else
		return false;
}
//????????
struct ListNode* reverseList(struct ListNode* head)
{
	if (head == NULL)
		return NULL;
	struct ListNode* prev = NULL;
	struct ListNode* ptr = head;
	while (ptr != NULL)
	{
		struct ListNode* temp = ptr->next;
		ptr->next = prev;
		prev = ptr;
		ptr = temp;
	}
	return prev;
}
//???0?????????
int countOperations(int num1, int num2)
{
	int k = 0;
	while (num1 != 0 && num2 != 0)
	{
		if (num1 >= num2)
		{
			num1 = num1 - num2;
			k++;
			continue;
		}
		if (num1 < num2)
		{
			num2 = num2 - num1;
			k++;
			continue;
		}
	}
	return k;
}
//?????????
int missingNumber(int* nums, int numsSize) {
	int x = 0;
	int i = 0;
	for (i = 0; i <= numsSize; i++)
	{
		x ^= i;
	}
	for (i = 0; i < numsSize; i++)
	{
		x ^= nums[i];
	}
	return x;
}
//???????
void reverse(int* nums, int left, int right)
{
	while (left < right)
	{
		int a = nums[left];
		nums[left] = nums[right];
		nums[right] = a;
		left++;
		right--;
	}
}
void rotate(int* nums, int numsSize, int k)
{
	if (k >= numsSize)
		k %= numsSize;
	//?n - k????????
	reverse(nums, 0, numsSize - k - 1);
	//??k????????
	reverse(nums, numsSize - k, numsSize - 1);
	//???????
	reverse(nums, 0, numsSize - 1);
}
//??????????
struct ListNode* removeElements(struct ListNode* head, int val)
{
	//???????????????????????
	struct ListNode* p = head;
	//????????????
	struct ListNode* ptr = head;
	while (p)
	{
		if (p->val == val)
		{
			struct ListNode* newnode = p->next;
			if (p == head)
				head = newnode;
			else
				ptr->next = newnode;
			free(p);
			p = newnode;
		}
		else if (p->val != val)
		{
			ptr = p;
			p = p->next;
		}
	}
	return head;
}
//???????????????
int intcompare(const void* a, const void* b)
{
	return (*(int*)b - *(int*)a);
}
int maxProduct(int* nums, int numsSize)
{
	qsort(nums, numsSize, sizeof(int), intcompare);
	return (nums[0] - 1) * (nums[1] - 1);
}
//??????????:
struct ListNode* middleNode(struct ListNode* head)
{
	int k = 0;
	int count = 0;
	struct ListNode* cur = head;
	struct ListNode* cur1 = head;
	while (cur != NULL)
	{
		count++;
		cur = cur->next;
	}
	if (count == 1)
		return head;
	k = count / 2;
	count = 0;
	while (cur1 != NULL)
	{
		count++;
		cur1 = cur1->next;
		if (count == k)
			return cur1;
	}
	return NULL;
}
//??????2.2 ??????????k?????
int kthToLast(struct ListNode* head, int k) {
	struct ListNode* pre = NULL;
	struct ListNode* cur = head;
	while (cur)
	{
		struct ListNode* next = cur->next;
		cur->next = pre;
		pre = cur;
		cur = next;
	}
	int i = 0;
	while (pre)
	{
		i++;
		if (i == k)
			return pre->val;
		pre = pre->next;
	}
	return -1;
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 //????????????????
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
	if (list1 == NULL)
		return list2;
	if (list2 == NULL)
		return list1;
	struct ListNode* head = NULL;
	struct ListNode* tail = NULL;
	while (list1 && list2)
	{
		if (list1->val > list2->val)
		{
			if (head == NULL)
			{
				head = list2;
				tail = list2;
			}
			else
			{
				tail->next = list2;
				tail = list2;
			}
			list2 = list2->next;
		}
		else
		{
			if (head == NULL)
			{
				head = list1;
				tail = list1;
			}
			else
			{
				tail->next = list1;
				tail = list1;
			}
			list1 = list1->next;
		}
	}
	if (list1 == NULL)
	{
		tail->next = list2;
	}
	if (list2 == NULL)
	{
		tail->next = list1;
	}
	return head;
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 //?????????
struct ListNode* deleteNode(struct ListNode* head, int val) {
	struct ListNode* cur = head;
	struct ListNode* prev = head;
	if (head->val == val)
	{
		head = cur->next;
		free(cur);
		cur->next == NULL;
		return head;
	}
	else
	{
		while (cur)
		{
			if (cur->val == val)
			{
				struct ListNode* next = cur->next;
				prev->next = next;
				free(cur);
				cur = next;
				break;
			}
			prev = cur;
			cur = cur->next;
		}
		return head;
	}
}
//???????
struct ListNode* reverseList(struct ListNode* head) {
	struct ListNode* cur = head;
	struct ListNode* prev = NULL;
	while (cur)
	{
		struct ListNode* next = cur->next;
		cur->next = prev;
		prev = cur;
		cur = next;
	}
	return prev;
}
//?????? ??????????
void deleteNode(struct ListNode* node) {
	struct ListNode* next = node->next;
	node->val = next->val;
	node->next = next->next;
	free(next);
	next = NULL;
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 //??????
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
	struct ListNode* ptr = headA;
	struct ListNode* ptr1 = headB;
	struct ListNode* cur = ptr;
	struct ListNode* cur1 = ptr1;
	int m = 0;
	int n = 0;
	while (cur)
	{
		m++;
		cur = cur->next;
	}
	while (cur1)
	{
		n++;
		cur1 = cur1->next;
	}
	int k = 0;
	if (m > n)
	{
		k = m - n;
		while (k > 0)
		{
			k--;
			ptr = ptr->next;
		}
	}
	else
	{
		k = n - m;
		while (k > 0)
		{
			k--;
			ptr1 = ptr1->next;
		}
	}
	while (ptr != ptr1)
	{
		ptr = ptr->next;
		ptr1 = ptr1->next;
		if (ptr == NULL || ptr1 == NULL)
			return NULL;
	}
	return ptr;
}
//????????????????
int getDecimalValue(struct ListNode* head) {
	struct ListNode* cur = head;
	struct ListNode* cur1 = head;
	int i = 0;
	while (cur)
	{
		i++;
		cur = cur->next;
	}
	int sum = 0;
	while (i)
	{
		sum += cur1->val * pow(2, (i - 1));
		i--;
		cur1 = cur1->next;
	}
	return sum;
}
//????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
bool isPalindrome(struct ListNode* head) {
	struct ListNode* cur = head;
	struct ListNode* cur1 = head;
	struct ListNode* cur2 = head;
	int k = 0;
	while (cur)
	{
		k++;
		cur = cur->next;
	}
	if (k == 0)
		return false;
	if (k == 1)
		return true;
	int* p = (int*)malloc(sizeof(int) * k);
	int i = 0;
	for (i = 0; i < k; i++)
	{
		*(p + i) = cur1->val;
		cur1 = cur1->next;
		if (cur1 == NULL)
			break;
	}
	struct ListNode* prev = NULL;
	while (cur2)
	{
		struct ListNode* next = cur2->next;
		cur2->next = prev;
		prev = cur2;
		cur2 = next;
	}
	int* h = (int*)malloc(sizeof(int) * k);
	int j = 0;
	for (j = 0; j < k; j++)
	{
		*(h + j) = prev->val;
		prev = prev->next;
		if (prev == NULL)
			break;
	}
	for (i = 0, j = 0; j < k && i < k; i++, j++)
	{
		if (*(p + i) != *(h + j))
			return false;
	}
	return true;
}
//????????
void exchange(char* str)
{
	char* str1 = str;
	int i = 0;
	int j = 0;
	for (i = 0; str[i] != '\0'; i++)
	{
		if ((str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
		{
			if (str[i] >= 'A' && str[i] <= 'Z')
			{
				str[i] += 32;
			}
			str1[j] = str[i];
			j++;
		}
	}
	str1[j] = '\0';
	str = str1;
}
bool isPalindrome(char* s) {
	//???????
	exchange(s);
	int sz = strlen(s);
	char* end = s + sz - 1;
	//???
	char* p = (char*)malloc(sizeof(char) * (sz + 1));
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		*(p + i) = *end;
		if (end == s)
			break;
		end--;
	}
	*(p + sz) = '\0';
	//???
	int j = 0;
	for (i = 0, j = 0; i < sz && j < sz; i++, j++)
	{
		if (*(p + i) != s[j])
		{
			return false;
		}
	}
	return true;
}
//??????????????
struct ListNode* deleteDuplicates(struct ListNode* head) {
	if (head == NULL)
		return NULL;
	struct ListNode* prev = head;
	struct ListNode* cur = prev->next;
	while (cur)
	{
		if (cur->val == prev->val)
		{
			struct ListNode* next = cur->next;
			prev->next = next;
			free(cur);
			if (prev == NULL)
				break;
			cur = prev->next;
		}
		else
		{
			prev = cur;
			cur = prev->next;
		}
	}
	return head;
}
//?????????
bool isPalindrome(int x) {
	if (x < 0)
		return false;
	if (x < 10)
		return true;
	int sum = 0;
	int n = x;
	int f = 0;
	int cout = 0;
	while (n)
	{
		cout++;
		n /= 10;
	}
	n = x;
	while (n)
	{
		f = n % 10;
		sum += (f * pow(10, (cout - 1)));
		cout--;
		n /= 10;
	}
	if (sum == x)
		return true;
	else
		return false;
}
//????????
bool hasCycle(struct ListNode* head) {
	struct ListNode* cur = head;
	int k = 0;
	while (cur)
	{
		k++;
		cur = cur->next;
		if (k == 100001)
			return true;
	}
	return false;
}
//????????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 /**
  * Definition for singly-linked list.
  * struct ListNode {
  *     int val;
  *     struct ListNode *next;
  * };
  */
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
	struct ListNode* cur = l1;
	struct ListNode* cur1 = l2;
	int k = 0;
	int n = 0;
	while (cur)
	{
		k++;
		cur = cur->next;
	}
	while (cur1)
	{
		n++;
		cur1 = cur1->next;
	}
	if (k > n)
	{
		struct ListNode* cur2 = l1;
		struct ListNode* cur3 = l2;
		struct ListNode* prev1 = NULL;
		struct ListNode* prev2 = NULL;
		while (cur2)
		{
			struct ListNode* next = cur2->next;
			cur2->next = prev1;
			prev1 = cur2;
			cur2 = next;
		}
		while (cur3)
		{
			struct ListNode* next = cur3->next;
			cur3->next = prev2;
			prev2 = cur3;
			cur3 = next;
		}
		cur2 = prev1;
		cur3 = prev2;
		int m = k - n;
		//??????????
		while (m > 0)
		{
			cur2 = cur2->next;
			m--;
		}
		while (cur2 && cur3)
		{
			cur2->val += cur3->val;
			cur2 = cur2->next;
			cur3 = cur3->next;
		}
		cur2 = prev1;
		struct ListNode* prev = NULL;
		//???????
		while (cur2)
		{
			struct ListNode* next = cur2->next;
			cur2->next = prev;
			prev = cur2;
			cur2 = next;
		}
		struct ListNode* cur4 = prev;
		//???
		while (cur4->next != NULL)
		{
			if (cur4->val > 9)
			{
				cur4->val %= 10;
				cur4->next->val += 1;
			}
			cur4 = cur4->next;
		}
		if (cur4->val <= 9)
			return prev;
		if (cur4->val > 9)
		{
			struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
			newnode->val = cur4->val / 10;
			newnode->next = NULL;
			cur4->val %= 10;
			cur4->next = newnode;
			return prev;
		}
	}
	else
	{
		struct ListNode* cur2 = l2;
		struct ListNode* cur3 = l1;
		struct ListNode* prev1 = NULL;
		struct ListNode* prev2 = NULL;
		while (cur2)
		{
			struct ListNode* next = cur2->next;
			cur2->next = prev1;
			prev1 = cur2;
			cur2 = next;
		}
		while (cur3)
		{
			struct ListNode* next = cur3->next;
			cur3->next = prev2;
			prev2 = cur3;
			cur3 = next;
		}
		cur2 = prev1;
		cur3 = prev2;
		int m = n - k;
		//??????????
		while (m > 0)
		{
			cur2 = cur2->next;
			m--;
		}
		while (cur2 && cur3)
		{
			cur2->val += cur3->val;
			cur2 = cur2->next;
			cur3 = cur3->next;
		}
		cur2 = prev1;
		//???????
		struct ListNode* prev = NULL;
		while (cur2)
		{
			struct ListNode* next = cur2->next;
			cur2->next = prev;
			prev = cur2;
			cur2 = next;
		}
		struct ListNode* cur4 = prev;
		//??????
		while (cur4->next != NULL)
		{
			if (cur4->val > 9)
			{
				cur4->val %= 10;
				cur4->next->val += 1;
			}
			cur4 = cur4->next;
		}
		if (cur4->val <= 9)
			return prev;
		if (cur4->val > 9)
		{
			struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
			newnode->val = cur4->val / 10;
			newnode->next = NULL;
			cur4->val %= 10;
			cur4->next = newnode;
			return prev;
		}
	}
	return NULL;
}
//???????
struct ListNode* partition(struct ListNode* head, int x) {
	int n = 0;
	int m = 0;
	struct ListNode* cur = head;
	while (cur)
	{
		if (cur->val >= x)
		{
			m++;
		}
		else
		{
			n++;
		}
		cur = cur->next;
	}
	int* p = (int*)malloc(sizeof(int) * m);
	int* t = (int*)malloc(sizeof(int) * n);
	int i = 0;
	cur = head;
	while (cur)
	{
		if (cur->val >= x)
		{
			*(p + i) = cur->val;
			i++;
		}
		cur = cur->next;
	}
	cur = head;
	int j = 0;
	while (cur)
	{
		if (cur->val < x)
		{
			*(t + j) = cur->val;
			j++;
		}
		cur = cur->next;
	}
	i = 0;
	j = 0;
	cur = head;
	while (cur)
	{
		while (j < n)
		{
			cur->val = *(t + j);
			j++;
			cur = cur->next;
		}
		while (i < m)
		{
			cur->val = *(p + i);
			i++;
			cur = cur->next;
		}
	}
	return head;
}
//LCR 126.??????
int fib(int n) {
	if (n == 0)
		return 0;
	long long a = 0;
	long long  b = 1;
	long long  c = 1;
	while (n >= 2)
	{
		a = a % 1000000007;
		b = b % 1000000007;
		c = a + b;
		a = b;
		b = c;
		n--;
	}
	return c % 1000000007;
}
//???????2
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseBetween(struct ListNode* head, int left, int right) {
	struct ListNode* cur = head;
	struct ListNode* left1 = head;
	struct ListNode* right1 = head;
	int m = 0;
	int n = 0;
	while (cur)
	{
		m++;
		n++;
		if (m == left)
			left1 = cur;
		if (n == right)
			right1 = cur;
		cur = cur->next;
	}
	if (left1 == head)
	{
		cur = head;
		struct ListNode* next = right1->next;
		right1->next = NULL;
		struct ListNode* prev = NULL;
		while (cur)
		{
			struct ListNode* next1 = cur->next;
			cur->next = prev;
			prev = cur;
			cur = next1;
		}
		head->next = next;
		return prev;
	}
	else
	{
		cur = head;
		struct ListNode* next = right1->next;
		while (cur->next != left1)
		{
			cur = cur->next;
		}
		struct ListNode* prev = cur;
		prev->next = NULL;
		right1->next = NULL;
		cur = left1;
		struct ListNode* prev2 = NULL;
		while (cur)
		{
			struct ListNode* next1 = cur->next;
			cur->next = prev2;
			prev2 = cur;
			cur = next1;
		}
		prev->next = prev2;
		left1->next = next;
		return head;
	}
}
//???????
int reverse(int x)
{
	if (x == -2147483648)
		return 0;
	if (x == -1563847412)
		return 0;
	int* intger = (int*)malloc(sizeof(int) * 31);
	int i = 0;
	int k = 0;
	int n = x;
	int sum = 0;
	while (n)
	{
		*(intger + i) = n % 10;
		i++;
		n /= 10;
	}
	k = i;
	int f = k;
	for (i = 0; i < k; i++)
	{
		sum += (*(intger + i) * pow(10, f - 1));
		if (x > 0)
		{
			if (sum < 0)
			{
				return 0;
			}
		}
		if (x < 0)
		{
			if (sum > 0)
			{
				return 0;
			}
		}
		f--;
	}
	return sum;
}
//???????????????N?????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
	struct ListNode* prev = NULL;
	struct ListNode* cur = head;
	while (cur)
	{
		struct ListNode* next = cur->next;
		cur->next = prev;
		prev = cur;
		cur = next;
	}
	cur = prev;
	int k = 0;
	struct ListNode* node = head;
	while (cur)
	{
		k++;
		if (k == n)
		{
			node = cur;
		}
		cur = cur->next;
	}
	if (node == prev)
	{
		prev = node->next;
		free(node);
		node = NULL;
		struct ListNode* prev1 = NULL;
		cur = prev;
		while (cur)
		{
			struct ListNode* next1 = cur->next;
			cur->next = prev1;
			prev1 = cur;
			cur = next1;
		}
		return prev1;
	}
	else
	{
		cur = prev;
		while (cur->next != node)
		{
			cur = cur->next;
		}
		cur->next = node->next;
		node->next = NULL;
		free(node);
		node = NULL;
		struct ListNode* prev1 = NULL;
		cur = prev;
		while (cur)
		{
			struct ListNode* next1 = cur->next;
			cur->next = prev1;
			prev1 = cur;
			cur = next1;
		}
		return prev1;
	}
}
//???????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* rotateRight(struct ListNode* head, int k) {
	if (head == NULL)
		return NULL;
	struct ListNode* cur = head;
	int h = 0;
	while (cur)
	{
		h++;
		cur = cur->next;
	}
	int* intger = (int*)malloc(sizeof(int) * h);
	k %= h;
	int i = 0;
	struct ListNode* cur1 = head;
	cur = head;
	int f = h - k;
	while (cur)
	{
		i++;
		cur = cur->next;
		if (i == f)
			break;
	}
	i = 0;
	while (cur && i < h)
	{
		*(intger + i) = cur->val;
		cur = cur->next;
		i++;
	}
	while (i < h)
	{
		*(intger + i) = cur1->val;
		cur1 = cur1->next;
		i++;
	}
	i = 0;
	cur1 = head;
	while (cur1 && (i < h))
	{
		cur1->val = *(intger + i);
		i++;
		cur1 = cur1->next;
	}
	return head;
}
//?????????????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* swapPairs(struct ListNode* head) {
	if (head == NULL)
		return NULL;
	struct ListNode* cur = head;
	struct ListNode* prev = cur;
	while (cur)
	{
		if (cur == head)
		{
			struct ListNode* next1 = cur->next;
			if (next1 == NULL)
				return head;
			prev->next = next1->next;
			next1->next = prev;
			head = next1;
			cur = next1->next;
			prev = cur;
			cur = cur->next;
		}
		else
		{
			struct ListNode* next1 = cur->next;
			if (next1 == NULL)
				return head;
			struct ListNode* next2 = next1->next;
			prev->next = next1;
			cur->next = next2;
			next1->next = cur;
			prev = cur;
			if (cur == NULL)
				break;
			cur = cur->next;
		}
	}
	return head;
}
//3.?????????????????????
int critic(char* cur, char* end)
{
	int k = 0;
	while (cur != end)
	{
		k++;
		cur++;
	}
	return k;
}
int critic1(char* cur, char* end)
{
	int k = 0;
	while (cur != end)
	{
		if (*cur == *end)
			return 0;
		cur++;
	}
	return 1;
}
int lengthOfLongestSubstring(char* s) {
	if (strlen(s) == 0)
		return 0;
	//?????????
	int* number = (int*)malloc(sizeof(int) * (strlen(s)));
	int i = 0;
	int f = 0;
	char* cur = s;
	char* start = s;
	char* end = s;
	while (*end != '\0')
	{
		if (end == start && *end != '\0')
		{
			end++;
		}
		if (*start != *end && *cur != *end && *end != '\0')
		{
			int flag = critic1(cur, end);
			if (flag == 1)
			{
				start = end;
				end++;
				if (*end == '\0')
				{
					int ret = critic(cur, end);
					*(number + i) = ret;
					i++;
					break;
				}
			}
			else
			{
				f = 1;
				if (*end == '\0')
				{
					break;
				}
				else
				{
					int ret = critic(cur, end);
					*(number + i) = ret;
					i++;
					cur++;
					end = start;
					end = cur;
				}
			}
		}
		else
		{
			if (*end == '\0')
			{
				break;
			}
			else
			{
				f = 1;
				int ret = critic(cur, end);
				printf("%d ", ret);
				*(number + i) = ret;
				i++;
				cur++;
				end = cur;
				start = cur;
			}
		}
	}
	if (f == 1)
	{
		int j = 0;
		int max = *(number + 0);
		for (j = 1; j < i; j++)
		{
			if (max < *(number + j))
				max = *(number + j);
		}
		return max;
	}
	else
	{
		return strlen(s);
	}
}
int critic(char* left, char* end)
{
	while (left < end)
	{
		if (*left != *end)
			return 0;
		left++;
		end--;
	}
	return 1;
}
int flag1(char* left, char* end)
{
	int i = 0;
	while (left != end)
	{
		if (*left == *end)
			return i;
		i++;
		left++;
	}
	return -1;
}
//?????????
char* longestPalindrome(char* s) {
	char string[1000][1000] = { '\0' };
	int i = 0;
	int j = 0;
	char* end = s;
	char* cur = s;
	while (*end != '\0') {
		if (cur == end) {
			end++;
		}
		if (*cur != *end) {
			int flag1 = critic1(cur, end);
			if (flag1 == -1)
			{
				end++;
			}
			else
			{
				char* cur1 = cur;
				cur = cur + i;
			}
		}
		else
		{
			int flag = critic(cur, end);
			if (flag == 0)
			{
				end++;
				cur++;
			}
			else
			{
				while (cur <= end)
				{
					string[i][j] = *cur;
					cur++;
					j++;
				}
				string[i][j] = '\0';
				int k = j;
				for (j = 0; j < k; j++)
				{
					printf("%c ", string[i][j]);
				}
				printf("\n");
				i++;
				j = 0;
			}
		}

	}
	return s;
}
//???????????????
bool isFascinating(int n) {
	int f = 2 * n;
	int k = 3 * n;
	int* number_t = (int*)malloc(sizeof(int) * 12);
	int i = 0;
	while (n)
	{
		*(number_t + i) = n % 10;
		i++;
		n /= 10;
	}
	while (f)
	{
		*(number_t + i) = f % 10;
		i++;
		f /= 10;
	}
	while (k)
	{
		*(number_t + i) = k % 10;
		i++;
		k /= 10;
	}
	if (i == 10)
		return false;
	int h = i;
	int s = 0;
	for (i = 0; i < h; i++)
	{
		if (*(number_t + i) == 0)
			return false;
	}
	for (i = 0; i < h; i++)
	{
		for (s = i + 1; s < h; s++)
		{
			if (*(number_t + i) == *(number_t + s))
				return false;
		}
	}
	return true;
}
//?????????
int critic(char* cur, char* end)
{
	while (cur < end)
	{
		if (*cur != *end)
			return 0;
		cur++;
		end--;
	}
	return 1;
}
int critic1(char* cur, char* end)
{
	int i = 0;
	while (cur != end)
	{
		i++;
		cur++;
	}
	i += 1;
	return i;
}
char* longestPalindrome(char* s) {
	char* ret = s;
	char* string = (char*)malloc(sizeof(char) * 1200);
	if (string == NULL)
	{
		return NULL;
	}
	int i = 0;
	int flag1 = 0;
	char* cur = s;
	char* end = s + strlen(s) - 1;
	while (*cur != '\0')
	{
		if (end == cur)
		{
			cur++;
			if (*cur == '\0')
				break;
			end = s + strlen(s);
		}
		int flag = critic(cur, end);
		if (flag == 0)
		{
			end--;
		}
		else
		{
			flag1 = 1;
			int number = critic1(cur, end);
			int k = i;
			if (number > k)
			{
				i = 0;
				char* string1 = cur;
				while (string1 <= end)
				{
					*(string + i) = *string1;
					string1++;
					i++;
				}
				*(string + i) = '\0';
				end--;
			}
			else
			{
				end--;
			}
		}
	}
	if (flag1 == 1)
		return string;
	else
	{
		i = 0;
		*(string + i) = s[i];
		i++;
		*(string + i) = '\0';
		return string;
	}
}
//???????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
int intcompare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
int numComponents(struct ListNode* head, int* nums, int numsSize) {
	struct ListNode* cur = head;
	int k = 0;
	while (cur)
	{
		k++;
		cur = cur->next;
	}
	int* number = (int*)malloc(sizeof(int) * k);
	if (number == NULL)
	{
		return 0;
	}
	int i = 0;
	while (i < k)
	{
		*(number + i) = i;
		i++;
	}
	qsort(nums, numsSize, sizeof(int), intcompare);
	int* number_t = (int*)malloc(sizeof(int) * k);
	i = 0;
	int j = 0;
	int f = 0;
	while (i < numsSize)
	{
		if (*(number + f) == nums[i])
		{
			f++;
			i++;
		}
		else
		{
			*(number_t + j) = *(number + f);
			j++;
			f++;
		}
	}
	if (j == 0)
		return 1;
	cur = head;
	int h = j;
	j = 0;
	k = 0;
	while (cur)
	{
		if (cur->val == *(number_t + j))
		{
			if (cur == head)
			{
				cur = cur->next;
				j++;
				if (j >= h)
					break;
				continue;
			}
			else if (cur->next == NULL)
			{
				cur = cur->next;
				j++;
				if (j >= h)
					break;
				continue;
			}
			else
			{
				k++;
				j++;
				if (j >= h)
					break;
				if (cur == NULL)
					break;
				cur = cur->next;
				if (cur->val == *(number_t + j))
				{
					cur = cur->next;
					continue;
				}
				else
				{
					continue;
				}
			}
		}
		cur = cur->next;
	}
	if (cur != NULL)
		return k + 1;
	else
		return k;
}
//???????
int sumOfMultiples(int n) {
	int sum = 0;
	int a = 1;
	while (a <= n)
	{
		if (a % 3 == 0 || a % 7 == 0 || a % 5 == 0)
		{
			sum += a;
		}
		a++;
	}
	return sum;
}
//LCR 141.????????
struct ListNode* trainningPlan(struct ListNode* head) {
	if (head == NULL)
		return NULL;
	struct ListNode* cur = head;
	struct ListNode* prev = NULL;
	while (cur)
	{
		struct ListNode* next = cur->next;
		cur->next = prev;
		prev = cur;
		cur = next;
	}
	return prev;
}
//????????????????
int charcompare(const void* a, const void* b)
{
	return (*(char*)a - *(char*)b);
}
bool isAnagram(char* s, char* t) {
	qsort(s, strlen(s), sizeof(char), charcompare);
	qsort(t, strlen(t), sizeof(char), charcompare);
	int ret = strcmp(s, t);
	if (ret == 0)
		return true;
	else
		return false;
}
//??????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int judge(int* nums1, int* nums2, int nums2Size)
{
	int i = 0;
	while (i < nums2Size)
	{
		if (*nums1 == nums2[i])
			return *nums1;
		i++;
	}
	return -1;
}
int judge1(int* date, int j, int date1)
{
	int i = 0;
	while (i < j)
	{
		if (*(date + i) == date1)
			return 0;
		i++;
	}
	return 1;
}
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize)
{
	if (nums1Size > nums2Size)
	{
		int* date = (int*)malloc(sizeof(int) * nums2Size);
		int j = 0;
		int i = 0;
		while (i < nums1Size)
		{
			int date1 = judge(nums1 + i, nums2, nums2Size);
			if (date1 == -1)
			{
				i++;
			}
			else
			{
				int flag = judge1(date, j, date1);
				if (flag == 0)
				{
					i++;
				}
				else
				{
					*(date + j) = date1;
					j++;
					i++;
				}
			}
		}
		*returnSize = j;
		return date;
	}
	else
	{
		int* date = (int*)malloc(sizeof(int) * nums1Size);
		int j = 0;
		int i = 0;
		while (i < nums2Size)
		{
			int date1 = judge(nums2 + i, nums1, nums1Size);
			if (date1 == -1)
			{
				i++;
			}
			else
			{
				int flag = judge1(date, j, date1);
				if (flag == 0)
				{
					i++;
				}
				else
				{
					*(date + j) = date1;
					j++;
					i++;
				}
			}
		}
		*returnSize = j;
		return date;
	}
}
//???????
int intcompare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
int majorityElement(int* nums, int numsSize)
{
	qsort(nums, numsSize, sizeof(int), intcompare);
	int i = numsSize / 2;
	return nums[i];
}
//???????????????????????????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int Bubblesort(int* nums, int numsSize, int target)
{
	int left = 0;
	int right = numsSize - 1;
	while (left <= right)
	{
		int mid = (left + right) / 2;
		if (nums[mid] == target)
		{
			return mid;
		}
		if (nums[mid] < target)
		{
			left = mid + 1;
		}
		else
		{
			right = mid - 1;
		}
	}
	return -1;
}
int* searchRange(int* nums, int numsSize, int target, int* returnSize) {
	int j = 0;
	int i = 0;
	if (numsSize == 0)
	{

		int* number = (int*)malloc(sizeof(int) * 2);
		for (i = 0; i < 2; i++)
		{
			*(number + i) = -1;
		}
		*returnSize = 2;
		return number;
	}
	int* number = (int*)malloc(sizeof(int) * 2);
	int ret = Bubblesort(nums, numsSize, target);
	printf("%d", ret);
	if (ret == -1)
	{
		int* number_t = (int*)malloc(sizeof(int) * 2);
		for (i = 0; i < 2; i++)
		{
			*(number_t + i) = -1;
		}
		*returnSize = 2;
		return number_t;
	}
	i = ret;
	j = ret;
	while (i >= 0)
	{
		i--;
		if (i < 0)
		{
			break;
		}
		if (nums[i] != target)
		{
			break;
		}
	}
	*(number + 0) = (i + 1);
	while (j < numsSize)
	{
		j++;
		if (j >= numsSize)
		{
			break;
		}
		if (nums[j] != target)
		{
			break;
		}
	}
	*(number + 1) = (j - 1);
	*returnSize = 2;
	return number;
}
//?????????????????II
int removeDuplicates(int* nums, int numsSize) {
	int i = 0;
	while (i < numsSize)
	{
		int k = nums[i];
		int j = 0;
		while (nums[i] == k)
		{
			j++;
			i++;
			if (i >= numsSize)
				break;
		}
		if (j > 2)
		{
			i -= (j - 2);
			int h = j - 2;
			while (h > 0)
			{
				int f = i;
				for (f = i; f < numsSize - 1; f++)
				{
					nums[f] = nums[f + 1];
				}
				h--;
				numsSize--;
			}
		}
	}
	return numsSize;
}
//82.????????????????????II;
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* deleteDuplicates(struct ListNode* head) {
	if (head == NULL)
		return NULL;
	struct ListNode* cur = head;
	int k = 0;
	while (cur)
	{
		k++;
		cur = cur->next;
	}
	cur = head;
	int* number = (int*)malloc(sizeof(int) * k);
	int j = 0;
	while (cur)
	{
		*(number + j) = cur->val;
		j++;
		cur = cur->next;
	}
	int i = 0;
	while (i < k - 1)
	{
		if (*(number + i) == *(number + i + 1))
		{
			int g = *(number + i);
			while (*(number + i) == g)
			{
				j = i;
				for (j = i; j < k - 1; j++)
				{
					*(number + j) = *(number + j + 1);
				}
				k--;
				if (i == k)
					break;
				if (k == 0)
					break;
			}
		}
		else
		{
			if (k == 0)
				break;
			i++;
		}
	}
	if (k != 0)
	{
		cur = head;
		i = 0;
		while (i < k)
		{
			if (cur == NULL)
				break;
			cur->val = *(number + i);
			i++;
			if (i == k)
				break;
			cur = cur->next;
		}
		cur->next = NULL;
		return head;
	}
	else
	{
		return NULL;
	}
}
//??????????
uint32_t reverseBits(uint32_t n) {
	int sum = 0;
	int k = 32;
	while (n)
	{
		sum += (n % 2) * pow(2, k - 1);
		n /= 2;
		k--;
	}
	return sum;
}
//??????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findPeaks(int* mountain, int mountainSize, int* returnSize) {
	int* number = (int*)malloc(sizeof(int) * mountainSize);
	int j = 0;
	int i = 1;
	for (i = 1; i < mountainSize - 1; i++)
	{
		if (mountain[i] > mountain[i - 1] && mountain[i] > mountain[i + 1])
		{
			*(number + j) = i;
			j++;
		}
	}
	*returnSize = j;
	if (j == 0)
		return NULL;
	return number;
}
//???????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
int judge(int integar, int* nums, int k)
{
	int i = 0;
	for (i = 0; i < k; i++)
	{
		if (nums[i] == integar)
			return 0;
	}
	return 1;
}
int numComponents(struct ListNode* head, int* nums, int numsSize) {

	int k = 0;
	//????cur??????????
	struct ListNode* cur = head;
	while (cur)
	{
		k++;
		cur = cur->next;
	}
	//???????????????number_t???????
	int* number_t = (int*)malloc(sizeof(int) * k);
	int h = k;
	int j = 0;
	//????????????head
	cur = head;
	//??count???????
	int count = 0;
	//?????????????????nums?????????????????number_t
	while (cur)
	{
		int flag = judge(cur->val, nums, numsSize);
		if (flag == 1)
		{
			*(number_t + j) = count;
			j++;
		}
		count++;
		cur = cur->next;
	}
	for (int l = 0; l < j; l++)
	{
		printf("%d ", *(number_t + l));
	}
	int i = 0;
	int f = 0;
	//???j????0,???j?0,????????????????????????????????????????????1??
	//??????0????????????
	if (j != 0) {
		if (j == 1)
		{
			if (*(number_t + 0) != 0 && *(number_t + 0) != h - 1)
				return 2;
			else
				return 1;
		}
		for (i = 0; i < j - 1; i++)
		{
			if (*(number_t + i) != 0 && i == 0)
			{
				f++;
			}
			if ((*(number_t + i + 1) - *(number_t + i)) != 1)
			{
				f++;
			}
		}
		if (*(number_t + j - 1) != h - 1)
		{
			f++;
		}
		return f;
	}
	else
	{
		return 1;
	}

}
//???????
//?????????string????????????:
int judge1(char* string, char letter, int k)
{
	int j = 0;
	int count = 0;
	while (*(string + j) != '\0')
	{
		if (letter == *(string + j))
			count++;
		j++;
	}
	return count;
}
//???arr?????????string????????????
int judge(char* string, char* arr, int k)
{
	int j = 0;
	while (*(string + j) != '\0')
	{
		int i = 0;
		char letter = *(string + j);
		int count = judge1(string, letter, k);
		for (i = 0; arr[i] != '\0'; i++)
		{
			if (letter == arr[i])
			{
				count--;
			}
		}
		if (count <= 0)
		{
			j++;
		}
		else
		{
			return 0;
		}
	}
	return 1;
}
char* shortestCompletingWord(char* licensePlate, char** words, int wordsSize)
{
	int i = 0;
	int count = 0;
	//???????????????????????????????
	for (i = 0; licensePlate[i] != '\0'; i++)
	{
		if (licensePlate[i] >= 'a' && licensePlate[i] <= 'z')
		{
			count++;
		}
		if (licensePlate[i] >= 'A' && licensePlate[i] <= 'Z')
		{
			licensePlate[i] += 32;
			count++;
		}
	}
	//????????????????????
	char* string = (char*)malloc(sizeof(char) * (count + 1));
	int j = 0;
	for (i = 0; licensePlate[i] != '\0'; i++)
	{
		if (licensePlate[i] >= 'a' && licensePlate[i] <= 'z')
		{
			*(string + j) = licensePlate[i];
			j++;
		}
	}
	*(string + j) = '\0';
	int k = j;
	j = 0;
	i = 0;
	int h = 0;
	int* date_num = (int*)malloc(sizeof(int) * wordsSize);
	while (i < wordsSize)
	{
		//???words[i]?????string????????????
		int flag = judge(string, words[i], k);
		if (flag == 1)
		{
			*(date_num + h) = i;
			h++;
			i++;
		}
		else
		{
			i++;
		}
	}
	if (h == 0)
		return NULL;
	else
	{
		int sz_min = strlen(words[*(date_num + 0)]);
		printf("%d ", sz_min);
		int q = *(date_num + 0);
		printf("\n");
		for (i = 1; i < h; i++)
		{
			int number = *(date_num + i);
			if (strlen(words[number]) < sz_min)
			{
				sz_min = strlen(words[number]);
				q = number;
			}
		}
		return words[q];
	}
}
//LCR 140.??????||
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* trainingPlan(struct ListNode* head, int cnt) {
	struct ListNode* cur = head;
	int k = 0;
	while (cur)
	{
		k++;
		cur = cur->next;
	}
	int f = k - cnt;
	int i = 0;
	cur = head;
	while (cur)
	{
		if (i == f)
			break;
		i++;
		cur = cur->next;
	}
	return cur;

}
//2903.????????????????????|
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findIndices(int* nums, int numsSize, int indexDifference, int valueDifference, int* returnSize) {
	int* index_t = (int*)malloc(sizeof(int) * 2);
	int f = 0;
	int i = 0;
	//????????
	while (i < numsSize)
	{
		int j = i + indexDifference;
		if (j >= numsSize)
		{
			break;
		}
		for (j = i + indexDifference; j < numsSize; j++)
		{
			if (abs(nums[i] - nums[j]) >= valueDifference)
			{
				*(index_t + 0) = i;
				*(index_t + 1) = j;
				f = 2;
			}
			if (f == 2)
				break;
		}
		if (f == 2)
			break;
		i++;
	}
	if (f == 0)
	{
		*(index_t + 0) = -1;
		*(index_t + 1) = -1;
		*returnSize = 2;
		return index_t;
	}
	else
	{
		*returnSize = f;
		return index_t;
	}
}
//?????????????????
int judge(int number1, int* number_t1, int total)
{
	int i = 0;
	int k = 0;
	for (i = 0; i < total; i++)
	{
		if (number1 == *(number_t1 + i))
		{
			k++;
		}
	}
	return k;
}
int* findMissingAndRepeatedValues(int** grid, int gridSize, int* gridColSize, int* returnSize) {
	int* number = (int*)malloc(sizeof(int) * 2);
	*returnSize = 2;
	int col = *gridColSize;
	int total = gridSize * (col);
	int* number_t = (int*)malloc(sizeof(int) * total);
	int* number_t1 = (int*)malloc(sizeof(int) * total);
	int i = 1;
	int j = 0;
	int f = 0;
	while (j < total)
	{
		*(number_t + j) = i;
		j++;
		i++;
	}
	for (i = 0; i < gridSize; i++)
	{
		for (j = 0; j < col; j++)
		{
			*(number_t1 + f) = grid[i][j];
			f++;
		}
	}
	i = 0;
	while (i < total)
	{
		int number1 = *(number_t + i);
		int flag = judge(number1, number_t1, total);
		if (flag == 2)
		{
			*(number + 0) = number1;
		}
		if (flag == 0)
		{
			*(number + 1) = number1;
		}
		i++;
	}
	return number;
}
//???????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
void inputorder(struct TreeNode* root, int* number, int* returnSize)
{
	if (root == NULL)
		return;
	inputorder(root->left, number, returnSize);
	number[(*returnSize)++] = root->val;
	inputorder(root->right, number, returnSize);
}
int* inorderTraversal(struct TreeNode* root, int* returnSize) {
	int* number = (int*)malloc(sizeof(int) * 1000);
	*returnSize = 0;
	inputorder(root, number, returnSize);
	return number;
}
//??????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
void inputorder(struct TreeNode* root, int* number, int* returnSize)
{
	if (root == NULL)
		return;
	inputorder(root->left, number, returnSize);
	inputorder(root->right, number, returnSize);
	number[(*returnSize)++] = root->val;
}
int* postorderTraversal(struct TreeNode* root, int* returnSize) {
	int* number = (int*)malloc(sizeof(int) * 1000);
	*returnSize = 0;
	inputorder(root, number, returnSize);
	return number;
}
//??????????????
void intputorder(struct TreeNode* root, int* number, int* returnSize)
{
	if (root == NULL)
		return;
	number[(*returnSize)++] = root->val;
	intputorder(root->left, number, returnSize);
	intputorder(root->right, number, returnSize);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
	int* number = (int*)malloc(sizeof(int) * 1000);
	*returnSize = 0;
	intputorder(root, number, returnSize);
	return number;
}
//????????????????
void preorder(struct TreeNode* root, int* node_size)
{
	if (root == NULL)
		return;
	(*node_size)++;
	preorder(root->left, node_size);
	preorder(root->right, node_size);
}
int countNodes(struct TreeNode* root) {
	int* node_size = (int*)malloc(sizeof(int));
	*node_size = 0;
	preorder(root, node_size);
	return *node_size;
}
//?????????
bool isSubsequence(char* s, char* t) {
	int i = 0;
	int j = 0;
	int sz = strlen(t);
	while (s[i] != '\0')
	{
		if (j < sz) {
			if (s[i] == t[j])
			{
				i++;
				j++;
			}
			else {
				j++;
			}
		}
		else {
			break;
		}
	}
	if (s[i] == '\0') {
		return true;
	}
	else {
		return false;
	}
}
//???????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

int maxDepth(struct TreeNode* root) {
	if (root == NULL)    return 0;
	else
	{
		int x, y;
		x = maxDepth(root->left);
		y = maxDepth(root->right);
		return (x > y ? x : y) + 1;
	}
}
//???????
int trailingZeroes(int n) {
	if (n == 0)
	{
		return 0;
	}
	int count = 0;
	while (n)
	{
		count += (n / 5);
		n /= 5;
	}
	return count;
}
//?????????????
int romanToInt(char* s) {
	int sum = 0;
	int i = strlen(s) - 1;
	for (i = strlen(s) - 1; i >= 0; i--)
	{
		if (i == 0)
		{
			if (s[i] == 'I')
				sum += 1;
			if (s[i] == 'V')
				sum += 5;
			if (s[i] == 'X')
				sum += 10;
			if (s[i] == 'L')
				sum += 50;
			if (s[i] == 'C')
				sum += 100;
			if (s[i] == 'D')
				sum += 500;
			if (s[i] == 'M')
				sum += 1000;
			break;
		}
		if (s[i] == 'V' || s[i] == 'X')
		{
			if (s[i] == 'V')
			{
				if (s[i - 1] == 'I')
				{
					sum += 4;
					i--;
					continue;
				}
				else {
					sum += 5;
				}
			}
			if (s[i] == 'X')
			{
				if (s[i - 1] == 'I')
				{
					sum += 9;
					i--;
					continue;
				}
				else {
					sum += 10;
				}
			}
		}
		if (s[i] == 'L' || s[i] == 'C')
		{
			if (s[i] == 'L')
			{
				if (s[i - 1] == 'X')
				{
					sum += 40;
					i--;
					continue;
				}
				else {
					sum += 50;
				}
			}
			if (s[i] == 'C')
			{
				if (s[i - 1] == 'X')
				{
					sum += 90;
					i--;
					continue;
				}
				else {
					sum += 100;
				}
			}
		}
		if (s[i] == 'D' || s[i] == 'M')
		{
			if (s[i] == 'D')
			{
				if (s[i - 1] == 'C')
				{
					sum += 400;
					i--;
					continue;
				}
				else {
					sum += 500;
				}
			}
			if (s[i] == 'M')
			{
				if (s[i - 1] == 'C')
				{
					sum += 900;
					i--;
					continue;
				}
				else {
					sum += 1000;
				}
			}
		}
		if (s[i] == 'I')
		{
			sum += 1;
		}
	}
	return sum;
}
//14.????????
char* longestCommonPrefix(char** strs, int strsSize) {
	int i = 1;
	int k = 0;
	int min = strlen(strs[0]);
	for (i = 1; i < strsSize; i++)
	{
		if (strlen(strs[i]) < min)
		{
			min = strlen(strs[i]);
		}
	}
	int j = 0;
	for (j = 0; j < min; j++)
	{
		i = 0;
		int flag = 0;
		for (i = 0; i < strsSize - 1; i++)
		{
			if (strs[i][j] != strs[i + 1][j])
			{
				flag = 1;
				break;
			}

		}
		if (flag == 1)
		{
			break;
		}
		k++;
	}
	if (k == 0)
	{
		char* ret = strs[0];
		strs[0][0] = '\0';
		return ret;
	}
	else {
		char* ret = strs[0];
		j = 0;
		for (j = 0; j < k; j++)
		{
			strs[0][j] = strs[0][j];
		}
		strs[0][j] = '\0';
		return ret;
	}
}
//67.?????????
char* addBinary(char* a, char* b) {
	int size_t_a = strlen(a);
	int size_t_b = strlen(b);
	if (size_t_a > size_t_b)
	{
		char* ret = a;
		int j = size_t_a - 1;
		int i = size_t_b - 1;
		for (i = strlen(b) - 1; i >= 0; i--)
		{
			if (b[i] == '1')
				a[j] += 1;
			j--;
		}
		j = size_t_a - 1;
		for (j = size_t_a - 1; j > 0; j--)
		{
			if (a[j] == '2')
			{
				a[j] = '0';
				a[j - 1] += 1;
			}
			else if (a[j] == '3')
			{
				a[j] = '1';
				a[j - 1] += 1;
			}
		}
		if (a[0] != '1')
		{
			if (a[0] == '2')
			{
				char* string = (char*)malloc(sizeof(char) * 10000);
				int i = 1;
				int j = 2;
				string[0] = '1';
				string[1] = '0';
				while (a[i] != '\0')
				{
					string[j] = a[i];
					i++;
					j++;
				}
				string[j] = '\0';
				return string;
			}
			if (a[0] == '3')
			{
				char* string = (char*)malloc(sizeof(char) * 1000);
				int i = 1;
				int j = 2;
				string[0] = '1';
				string[1] = '1';
				while (a[i] != '\0')
				{
					string[j] = a[i];
					i++;
					j++;
				}
				string[j] = '\0';
				return string;
			}
		}
		else
		{
			return ret;
		}
	}
	else
	{
		char* ret = b;
		int j = size_t_b - 1;
		int i = size_t_a - 1;
		printf("%d\n", i);
		for (i = size_t_a - 1; i >= 0; i--)
		{

			if (a[i] == '1')
			{
				b[j] += 1;
			}
			j--;
		}
		printf("%s\n", b);
		j = size_t_b - 1;
		for (j = size_t_b - 1; j > 0; j--)
		{
			if (b[j] == '2')
			{
				b[j] = '0';
				b[j - 1] += 1;
			}
			else if (b[j] == '3')
			{
				b[j] = '1';
				b[j - 1] += 1;
			}
		}
		printf("%s", b);
		if (b[0] != '1')
		{
			if (b[0] == '2')
			{
				char* string = (char*)malloc(sizeof(char) * 1000);
				int i = 1;
				int j = 2;
				string[0] = '1';
				string[1] = '0';
				while (b[i] != '\0')
				{
					string[j] = b[i];
					i++;
					j++;
				}
				string[j] = '\0';
				return string;
			}
			if (b[0] == '3')
			{
				char* string = (char*)malloc(sizeof(char) * 1000);
				int i = 1;
				int j = 2;
				string[0] = '1';
				string[1] = '1';
				while (b[i] != '\0')
				{
					string[j] = b[i];
					i++;
					j++;
				}
				string[j] = '\0';
				return string;
			}
		}
		else
		{
			return ret;
		}
	}
	return a;
}
//3038.???????????????????
int maxOperations(int* nums, int numsSize) {
	int* number = (int*)malloc(sizeof(int) * 100);
	int f = 0;
	int i = 0;
	int j = 1;
	while (i < numsSize && j < numsSize)
	{
		int sum = nums[i] + nums[j];
		number[f] = sum;
		f++;
		i = i + 2;
		j = j + 2;
	}
	int count = 1;
	i = 0;
	for (i = 0; i < f - 1; i++)
	{
		if (number[i] == number[i + 1])
		{
			count++;
		}
		else {
			break;
		}
	}
	return count;
}
//?????????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* productExceptSelf(int* nums, int numsSize, int* returnSize) {
	int* answer = (int*)malloc(sizeof(int) * numsSize);
	*returnSize = numsSize;
	int k = 0;
	int flag = 1;
	int i = 0;
	int mul = 1;
	for (i = 0; i < numsSize; i++)
	{
		if (nums[i] == 0 && flag == 1)
		{
			flag = 0;
			k = i;
			continue;
		}
		mul *= nums[i];
	}
	if (mul != 0)
	{
		if (flag == 1)
		{
			for (i = 0; i < numsSize; i++)
			{
				answer[i] = mul / (nums[i]);
			}
		}
		else {
			for (i = 0; i < numsSize; i++)
			{
				if (i == k)
				{
					answer[i] = mul;
					continue;
				}
				answer[i] = 0;
			}
		}
		return answer;
	}
	else {
		for (i = 0; i < numsSize; i++)
		{
			answer[i] = 0;
		}
		return answer;
	}
}
int Binary_search(int* arr, int length, int target)
{
	int left = 0;
	int right = length - 1;
	while (left <= right)
	{
		int mid = (left + right) / 2;
		if (arr[mid] == target)
		{
			return 1;
		}
		else if (target > arr[mid]) {
			left = mid + 1;
		}
		else {
			right = mid - 1;
		}
	}
	return 0;
}
//???????????
bool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target) {
	int col = *matrixColSize;
	int total = matrixSize * col;
	int* arr = (int*)malloc(sizeof(int) * total);
	int len = 0;
	int i = 0;
	int j = 0;
	for (i = 0; i < matrixSize; i++)
	{
		for (j = 0; j < col; j++)
		{
			arr[len] = matrix[i][j];
			len++;
		}
	}
	int ret = Binary_search(arr, len, target);
	if (ret == 1)
		return true;
	else
		return false;
}
//???????
/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** generate(int numRows, int* returnSize, int** returnColumnSizes) {
	int** triangle = (int**)malloc(sizeof(int*) * numRows);
	int i = 0;
	int j = 1;
	for (i = 0; i < numRows; i++)
	{
		triangle[i] = (int*)malloc(sizeof(int) * j);
		j++;
	}
	*returnSize = numRows;
	i = 0;
	j = 0;
	for (i = 0; i < numRows; i++)
	{
		for (j = 0; j <= i; j++)
		{
			if (j == 0)
				*(*(triangle + i) + j) = 1;
			else if (j == i)
				*(*(triangle + i) + j) = 1;
			else {
				*(*(triangle + i) + j) = *(*(triangle + i - 1) + j) + *(*(triangle + i - 1) + j - 1);
			}
		}
	}
	*returnColumnSizes = (int*)malloc(sizeof(int) * (*returnSize));
	i = 0;
	j = 1;
	for (i = 0; i < (*returnSize); i++)
	{
		(*returnColumnSizes)[i] = j;
		j++;
	}
	return triangle;
}
//???????II
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* getRow(int rowIndex, int* returnSize) {
	int order = rowIndex + 1;
	int** triangle = (int**)malloc(sizeof(int*) * order);
	int i = 0;
	int l = 1;
	for (i = 0; i < order; i++)
	{
		triangle[i] = (int*)malloc(sizeof(int) * l);
		l++;
	}
	int j = 0;
	for (i = 0; i < order; i++)
	{
		for (j = 0; j <= i; j++)
		{
			if (j == 0) {
				triangle[i][j] = 1;
			}
			else if (j == i) {
				triangle[i][j] = 1;
			}
			else {
				triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
			}
		}
	}
	int* number = (int*)malloc(sizeof(int) * order);
	*returnSize = order;
	int f = 0;
	j = 0;
	for (j = 0; j < order; j++)
	{
		number[f] = triangle[rowIndex][j];
		f++;
	}
	return number;
}
//????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
int intcompare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
struct ListNode* sortList(struct ListNode* head) {
	if (head == NULL)
	{
		return NULL;
	}
	int k = 0;
	struct ListNode* cur = head;
	while (cur)
	{
		k++;
		cur = cur->next;
	}
	int* number = (int*)malloc(sizeof(int) * k);
	cur = head;
	int i = 0;
	while (cur)
	{
		number[i] = cur->val;
		i++;
		cur = cur->next;
	}
	qsort(number, k, sizeof(int), intcompare);
	i = 0;
	cur = head;
	while (cur)
	{
		cur->val = number[i];
		i++;
		cur = cur->next;
	}
	return head;
}
int Binary_search(int* number, int numsSize, int target)
{
	int left = 0;
	int right = numsSize - 1;
	while (left <= right)
	{
		int mid = (left + right) / 2;
		if (number[mid] == target)
			return number[mid];
		else if (number[mid] < target) {
			left = mid + 1;
		}
		else {
			right = mid - 1;
		}
	}
	return -1;
}
//???????????????
int search(int* nums, int numsSize, int target) {
	int min = 0;
	int i = 1;
	for (i = 1; i < numsSize; i++) {
		if (nums[i] < nums[min])
			min = i;
	}
	int k = min;
	int* number = (int*)malloc(sizeof(int) * numsSize);
	int j = 0;
	int f = 0;
	while (min < numsSize)
	{
		number[f] = nums[min];
		min++;
		f++;
	}
	while (j < k)
	{
		number[f] = nums[j];
		j++;
		f++;
	}
	int ret = Binary_search(number, f, target);
	if (ret == -1)
	{
		return -1;
	}
	else {
		i = 0;
		for (i = 0; i < numsSize; i++)
		{
			if (nums[i] == ret)
			{
				break;
			}
		}
		return i;
	}
}
//???????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
void preorder_traver(struct TreeNode* root, int* number, int* length)
{
	if (root == NULL)
	{
		number[(*length)++] = 10001;
		return;
	}
	number[(*length)++] = root->val;
	preorder_traver(root->left, number, length);
	preorder_traver(root->right, number, length);
}
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
	int* p_length = (int*)malloc(sizeof(int));
	*p_length = 0;
	int* q_length = (int*)malloc(sizeof(int));
	*q_length = 0;
	int* number_p = (int*)malloc(sizeof(int) * 1000);
	int* number_q = (int*)malloc(sizeof(int) * 1000);
	preorder_traver(p, number_p, p_length);
	preorder_traver(q, number_q, q_length);
	int i = 0;
	if ((*p_length) != (*q_length))
		return false;
	for (i = 0; i < (*p_length); i++)
	{
		if (number_p[i] != number_q[i])
		{
			return false;
		}
	}
	return true;
}
//??????????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
void preorder_travel(struct TreeNode* root, int* number, int* length)
{
	if (root == NULL)
		return;
	preorder_travel(root->left, number, length);
	preorder_travel(root->right, number, length);
	number[(*length)++] = root->val;
}
int getMinimumDifference(struct TreeNode* root) {
	int* number = (int*)malloc(sizeof(int) * 10000);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	preorder_travel(root, number, length);
	int i = 0;
	int j = 0;
	int flag1 = 1;
	int min = 0;
	for (i = 0; i < *length; i++)
	{
		for (j = i + 1; j < *length; j++)
		{
			if (flag1 == 1)
			{
				flag1 = 0;
				min = abs(number[j] - number[i]);
			}
			else if ((abs(number[j] - number[i]) < min) && flag1 == 0) {
				min = abs(number[j] - number[i]);
			}
		}
	}
	return min;
}
//??????????????k??????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
int intcompare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
void Preoder_trave(struct TreeNode* root, int* number, int* length)
{
	if (root == NULL)
		return;
	number[(*length)++] = root->val;
	Preoder_trave(root->left, number, length);
	Preoder_trave(root->right, number, length);
}
int kthSmallest(struct TreeNode* root, int k) {
	int* number = (int*)malloc(sizeof(int) * 10000);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	Preoder_trave(root, number, length);
	qsort(number, *length, sizeof(int), intcompare);
	int i = 0;
	for (i = 0; i < *length; i++)
	{
		if (i == k - 1)
		{
			return number[i];
		}
	}
	return 0;
}
//????????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
void preorder_travel(struct TreeNode* root, int* number, int* length)
{
	if (root == NULL)
		return;
	preorder_travel(root->left, number, length);
	preorder_travel(root->right, number, length);
	number[(*length)++] = root->val;
}
int minDiffInBST(struct TreeNode* root) {
	int* number = (int*)malloc(sizeof(int) * 10000);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	preorder_travel(root, number, length);
	int i = 0;
	int j = 0;
	int flag1 = 1;
	int min = 0;
	for (i = 0; i < *length; i++)
	{
		for (j = i + 1; j < *length; j++)
		{
			if (flag1 == 1)
			{
				flag1 = 0;
				min = abs(number[j] - number[i]);
			}
			else if ((abs(number[j] - number[i]) < min) && flag1 == 0) {
				min = abs(number[j] - number[i]);
			}
		}
	}
	return min;
}
//?????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* countBits(int n, int* returnSize) {
	int count = 0;
	int number = 0;
	while (number <= n)
	{
		count++;
		number++;
	}
	int* number_t = (int*)malloc(sizeof(int) * count);
	int k = count;
	number = 0;
	count = 0;
	int f = 0;
	while (number <= n)
	{
		int numbers = number;
		count = 0;
		while (numbers)
		{
			if (numbers & 1 == 1)
			{
				count++;
			}
			numbers = numbers >> 1;
		}
		printf("%d ", count);
		number_t[f] = count;
		f++;
		number++;
	}
	*returnSize = k;
	return number_t;
}
//??????
void rotate(int** matrix, int matrixSize, int* matrixColSize) {
	int col = *matrixColSize;
	int total = matrixSize * col;
	int* number = (int*)malloc(sizeof(int) * total);
	int f = 0;
	int i = 0;
	int j = 0;
	for (i = 0; i < matrixSize; i++)
	{
		for (j = 0; j < col; j++)
		{
			number[f] = matrix[i][j];
			f++;
		}
	}
	j = col - 1;
	i = 0;
	f = 0;
	for (j = col - 1; j >= 0; j--)
	{
		for (i = 0; i < matrixSize; i++)
		{
			matrix[i][j] = number[f];
			f++;
		}
	}
}
//????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* spiralOrder(int** matrix, int matrixSize, int* matrixColSize, int* returnSize) {
	int col = *matrixColSize;
	int total = col * matrixSize;
	int* number = (int*)malloc(sizeof(int) * total);
	int i = 0;
	int j = 0;
	int f = 0;
	while (f < total)
	{
		int i_t = i;
		int j_t = j;
		while (j_t < col - j)
		{
			if (f >= total)
				break;
			number[f] = matrix[i_t][j_t];
			f++;
			j_t++;
		}
		if (f >= total)
		{
			break;
		}
		j_t--;
		i_t++;
		while (i_t < matrixSize - i)
		{
			if (f >= total)
				break;
			number[f] = matrix[i_t][j_t];
			f++;
			i_t++;
		}
		if (f >= total)
		{
			break;
		}
		i_t--;
		j_t--;
		while (j_t >= j)
		{
			if (f >= total)
				break;
			number[f] = matrix[i_t][j_t];
			f++;
			j_t--;
		}
		if (f >= total)
		{
			break;
		}
		j_t++;
		i_t--;
		while (i_t > i)
		{
			if (f >= total)
				break;
			number[f] = matrix[i_t][j_t];
			f++;
			i_t--;
		}
		if (f >= total)
		{
			break;
		}
		i++;
		j++;
	}
	*returnSize = total;
	return number;
}
//????????
void setZeroes(int** matrix, int matrixSize, int* matrixColSize) {
	int col = *matrixColSize;
	int row = matrixSize;
	int i = 0;
	int j = 0;
	int** zero_collection = (int**)malloc(sizeof(int*) * 40000);
	for (i = 0; i < 40000; i++)
	{
		zero_collection[i] = (int*)malloc(sizeof(int) * 2);
	}
	int f = 0;
	for (i = 0; i < row; i++)
	{
		for (j = 0; j < col; j++)
		{
			if (matrix[i][j] == 0)
			{
				zero_collection[f][0] = i;
				zero_collection[f][1] = j;
				f++;
			}
		}
	}
	i = 0;
	while (i < f)
	{
		int i1 = zero_collection[i][0];
		int j1 = zero_collection[i][1];
		int k = j1 + 1;
		while (k < col)
		{
			matrix[i1][k] = 0;
			k++;
		}
		k = j1 - 1;
		while (k >= 0)
		{
			matrix[i1][k] = 0;
			k--;
		}
		int f1 = i1 + 1;
		while (f1 < row)
		{
			matrix[f1][j1] = 0;
			f1++;
		}
		f1 = i1 - 1;
		while (f1 >= 0)
		{
			matrix[f1][j1] = 0;
			f1--;
		}
		i++;
	}
}
//?????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
void Preorder_trave(struct TreeNode* root, int* number, int* length)
{
	if (root == NULL)
	{
		return;
	}
	number[(*length)++] = root->val;
	Preorder_trave(root->left, number, length);
	Preorder_trave(root->right, number, length);
}
bool isUnivalTree(struct TreeNode* root) {
	int* number = (int*)malloc(sizeof(int) * 100);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	Preorder_trave(root, number, length);
	int i = 0;
	int k = *length;
	for (i = 0; i < k - 1; i++)
	{
		if (number[i] != number[i + 1])
		{
			return false;
		}
	}
	return true;
}
//Lcr 142.??????IV
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
int compare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
struct ListNode* trainningPlan(struct ListNode* l1, struct ListNode* l2) {
	if (l1 == NULL && l2 == NULL)
		return NULL;
	if (l1 == NULL)
		return l2;
	if (l2 == NULL)
		return l1;
	struct ListNode* cur = l1;
	struct ListNode* cur1 = l2;
	int count = 0;
	while (cur)
	{
		count++;
		cur = cur->next;
	}
	while (cur1)
	{
		count++;
		cur1 = cur1->next;
	}
	int* number = (int*)malloc(sizeof(int) * count);
	int f = 0;
	cur = l1;
	cur1 = l2;
	while (cur)
	{
		number[f] = cur->val;
		f++;
		cur = cur->next;
	}
	while (cur1)
	{
		number[f] = cur1->val;
		f++;
		cur1 = cur1->next;
	}
	qsort(number, count, sizeof(int), compare);
	cur = l1;
	cur1 = l2;
	while (cur->next != NULL)
	{
		cur = cur->next;
	}
	f = 0;
	cur->next = l2;
	cur = l1;
	while (cur)
	{
		cur->val = number[f];
		f++;
		cur = cur->next;
	}
	return l1;
}
//????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
void Preorder_trave(struct TreeNode* root, int* number, int* length)
{
	if (root == NULL)
		return;
	number[(*length)++] = root->val;
	Preorder_trave(root->left, number, length);
	Preorder_trave(root->right, number, length);
}
int compare(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
int findSecondMinimumValue(struct TreeNode* root) {
	int* number = (int*)malloc(sizeof(int) * 25);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	Preorder_trave(root, number, length);
	int judge = number[0];
	int k = 0;
	int i = 0;
	for (i = 0; i < *length; i++)
	{
		if (number[i] == judge)
			k++;
	}
	if (k == *length)
		return -1;
	qsort(number, *length, sizeof(int), compare);
	for (i = 0; i < *length - 1; i++)
	{
		if (number[i] != number[i + 1])
			break;
	}
	return number[i + 1];
}
//H???
int intcompare(const void* a, const void* b)
{
	return (*(int*)a - *(int*)b);
}
int hIndex(int* citations, int citationsSize) {
	qsort(citations, citationsSize, sizeof(int), intcompare);
	int i = 0;
	int* number = (int*)malloc(sizeof(int) * 5000);
	int f = 0;
	int flag1 = 0;
	while (i < citationsSize)
	{
		int h = citations[i];
		int j = i;
		int count = 0;
		while (j < citationsSize)
		{
			count++;
			j++;
		}
		if (count >= h)
		{
			number[f] = h;
			f++;
			i++;
		}
		else {
			flag1 = 1;
			break;
		}
	}
	if (flag1 == 0)
	{
		return citations[citationsSize - 1];
	}
	else {
		int h = citations[i];
		h--;
		while (h > 0)
		{
			int k = i;
			int count = 0;
			while (k < citationsSize)
			{
				count++;
				k++;
			}
			if (count >= h)
			{
				break;
			}
			else {
				h--;
			}
		}
		if (f == 0)
		{
			return h;
		}
		else {
			int max = number[0];
			for (i = 1; i < f; i++)
			{
				if (number[i] > max)
					max = number[i];
			}
			if (max > h)
			{
				return max;
			}
			else {
				return h;
			}
		}
	}
}
//??????????
int xorOperation(int n, int start) {
	int* number = (int*)malloc(sizeof(int) * n);
	int i = 0;
	for (i = 0; i < n; i++)
	{
		number[i] = start + 2 * i;
	}
	int number1 = number[0];
	for (i = 1; i < n; i++)
	{
		number1 = number1 ^ number[i];
	}
	return number1;
}
//?????????
void bubble_sort(int* nums, int numsSize)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < numsSize - 1; i++)
	{
		for (j = 0; j < numsSize - 1 - i; j++)
		{
			if (nums[j] < nums[j + 1])
			{
				int temp = nums[j + 1];
				nums[j + 1] = nums[j];
				nums[j] = temp;
			}
		}
	}
}
int thirdMax(int* nums, int numsSize) {
	int i = 0;
	bubble_sort(nums, numsSize);
	if (numsSize < 3)
	{
		return nums[0];
	}
	int* number = (int*)malloc(sizeof(int) * 3);
	int f = 0;
	for (i = 0; i < numsSize; i++)
	{
		int temp = nums[i];
		int flag1 = 1;
		int l = 0;
		for (l = 0; l < f; l++)
		{
			if (temp == number[l])
			{
				flag1 = 0;
				break;
			}
		}
		if (flag1 == 1)
		{
			number[f] = temp;
			f++;
		}
		if (f == 3)
		{
			break;
		}
	}
	if (f < 3)
	{
		return number[0];
	}
	return number[3 - 1];
}
//1207 ??????????
int compare(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
bool uniqueOccurrences(int* arr, int arrSize) {
	int* number = (int*)malloc(sizeof(int) * 1000);
	int i = 0;
	int f = 0;
	int flag1 = 1;
	for (i = 0; i < arrSize; i++)
	{
		int flag = 1;
		int j = 0;
		if (flag1 == 1)
		{
			number[f] = arr[i];
			f++;
			flag1 = 0;
		}
		for (j = 0; j < f; j++)
		{
			if (arr[i] == number[j])
			{
				flag = 0;
				break;
			}
		}
		if (flag == 1)
		{
			number[f] = arr[i];
			f++;
		}
	}
	int* count = (int*)malloc(sizeof(int) * f);
	for (i = 0; i < f; i++)
	{
		int count1 = 0;
		int j = 0;
		for (j = 0; j < arrSize; j++)
		{
			if (number[i] == arr[j])
			{
				count1++;
			}
		}
		count[i] = count1;
	}
	qsort(count, f, sizeof(int), compare);
	for (i = 0; i < f - 1; i++)
	{
		if (count[i] == count[i + 1])
		{
			return false;
		}
	}
	return true;
}
//???????????
bool isUnique(char* astr) {
	int i = 0;
	int sz = strlen(astr);
	while (i < sz)
	{
		int i_1 = i - 1;
		int i_2 = i + 1;
		int count = 0;
		while (i_1 >= 0)
		{
			if (astr[i] == astr[i_1])
				count++;
			i_1--;
		}
		while (i_2 < sz)
		{
			if (astr[i] == astr[i_2])
				count++;
			i_2++;
		}
		if (count != 0)
			return false;
		i++;

	}
	return true;
}
//??????????????if-else??????????
int maximum(int a, int b) {
	while (a < b)
	{
		a = a ^ b;
		b = a ^ b;
		a = a ^ b;
	}
	return a;
}
//????????????????
int findLucky(int* arr, int arrSize) {
	int* number = (int*)malloc(sizeof(int) * 500);
	int f = 0;
	int i = 0;
	for (i = 0; i < arrSize; i++)
	{
		int temp = arr[i];
		int count = 0;
		int j = 0;
		for (j = 0; j < arrSize; j++)
		{
			if (arr[j] == temp)
			{
				count++;
			}
		}
		if (count == temp)
		{
			number[f] = temp;
			f++;
		}
	}
	if (f != 0)
	{
		int max = number[0];
		for (i = 1; i < f; i++)
		{
			if (number[i] > max)
				max = number[i];
		}
		return max;
	}
	else {
		return -1;
	}

}
//???????1?????
int findMaxConsecutiveOnes(int* nums, int numsSize) {
	int* index = (int*)malloc(sizeof(int) * numsSize);
	int f = 0;
	int i = 0;
	for (i = 0; i < numsSize; i++)
	{
		if (nums[i] == 0)
		{
			index[f] = i;
			f++;
		}
	}
	if (f != 0)
	{
		int* number_t = (int*)malloc(sizeof(int) * (10000));
		int f_1 = 0;
		number_t[f_1] = index[0] - 0;
		f_1++;
		for (i = 0; i < f - 1; i++)
		{
			number_t[f_1] = index[i + 1] - index[i] - 1;
			f_1++;
		}
		number_t[f_1] = numsSize - index[f - 1] - 1;
		f_1++;
		int max = number_t[0];
		for (i = 1; i < f_1; i++)
		{
			if (number_t[i] > max)
				max = number_t[i];
		}
		return max;
	}
	else {
		return numsSize;
	}
}
//???????
int sumOfUnique(int* nums, int numsSize) {
	int* number = (int*)malloc(sizeof(int) * 100);
	int f = 0;
	int i = 0;
	while (i < numsSize)
	{
		int temp = nums[i];
		int j = 0;
		int count = 0;
		int i_1 = i - 1;
		int i_2 = i + 1;
		while (i_1 >= 0)
		{
			if (temp == nums[i_1])
			{
				count++;
			}
			i_1--;
		}
		while (i_2 < numsSize)
		{
			if (temp == nums[i_2])
			{
				count++;
			}
			i_2++;
		}
		if (count == 0)
		{
			number[f] = temp;
			f++;
		}
		i++;
	}
	if (f != 0)
	{
		int sum = 0;
		for (i = 0; i < f; i++)
		{
			sum += number[i];
		}
		return sum;
	}
	else {
		return 0;
	}
}
//??????????????
int subtractProductAndSum(int n) {
	int* number = (int*)malloc(sizeof(int) * 7);
	int f = 0;
	while (n)
	{
		number[f] = n % 10;
		f++;
		n /= 10;
	}
	int mul = 1;
	int sum = 0;
	int i = 0;
	for (i = 0; i < f; i++)
	{
		mul *= number[i];
		sum += number[i];
	}
	int sub = mul - sum;
	return sub;
}
//?????????
int mySqrt(int x) {
	return (int)sqrt(x);
}
//????????????
bool isSameAfterReversals(int num) {
	int number = num;
	int count = 0;
	while (number)
	{
		count++;
		number /= 10;
	}
	number = num;
	int sum = 0;
	while (number)
	{
		sum += ((number % 10) * pow(10, count - 1));
		count--;
		number /= 10;
	}
	printf("%d ", sum);
	int number1 = sum;
	count = 0;
	int sum1 = 0;
	while (number1)
	{
		count++;
		number1 /= 10;
	}
	number1 = sum;
	while (number1)
	{
		sum1 += ((number1 % 10) * pow(10, count - 1));
		count--;
		number1 /= 10;
	}
	printf("%d ", sum1);
	if (sum1 == num)
	{
		return true;
	}
	else {
		return false;
	}
	return 0;
}
//??????
bool checkPerfectNumber(int num) {
	if (num == 0 || num == 1)
	{
		return false;
	}
	int number = 1;
	int sum = 0;
	for (number = 1; number <= num / 2; number++)
	{
		if (num % number == 0)
		{
			sum += number;
		}
	}
	if (sum == num)
	{
		return true;
	}
	else {
		return false;
	}
}
//??????
int compare(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
int majorityElement(int* nums, int numsSize) {
	qsort(nums, numsSize, sizeof(int), compare);
	int i = numsSize / 2;
	int temp = nums[i];
	int j = 0;
	int count = 0;
	for (j = 0; j < numsSize; j++)
	{
		if (nums[j] == temp)
		{
			count++;
		}
	}
	if (count > numsSize / 2)
		return nums[i];
	else
		return -1;

}
//???????
int search(int* nums, int numsSize, int target) {
	int left = 0;
	int right = numsSize - 1;
	while (left <= right)
	{
		int mid = (left + right) / 2;
		if (nums[mid] == target)
			return mid;
		else if (nums[mid] > target)
			right = mid - 1;
		else
			left = left + 1;
	}
	return -1;
}
//????????
bool isMonotonic(int* nums, int numsSize) {
	int flag1 = 1;
	int flag2 = 1;
	int i = 0;
	for (i = 0; i < numsSize - 1; i++)
	{
		if (nums[i] < nums[i + 1])
		{
			flag1 = 0;
			break;
		}
	}
	if (flag1 == 1)
	{
		return true;
	}
	else {
		for (i = 0; i < numsSize - 1; i++)
		{
			if (nums[i] > nums[i + 1])
			{
				flag2 = 0;
				break;
			}
		}
		if (flag2 == 1)
		{
			return true;
		}
		else {
			return false;
		}
	}

}
//????????0?????????
int numberOfSteps(int num) {
	if (num == 0)
		return 0;
	int count = 0;
	while (num)
	{
		if (num % 2 == 0)
		{
			num /= 2;
			count++;
		}
		else {
			num -= 1;
			count++;
		}
	}
	return count;
}
//???????||
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
	struct ListNode* cur1 = l1;
	struct ListNode* cur2 = l2;
	int count_1 = 0;
	int count_2 = 0;
	while (cur1)
	{
		count_1++;
		cur1 = cur1->next;
	}
	while (cur2)
	{
		count_2++;
		cur2 = cur2->next;
	}
	int* number1 = (int*)malloc(sizeof(int) * count_1);
	int* number2 = (int*)malloc(sizeof(int) * count_2);
	cur1 = l1;
	cur2 = l2;
	int i_1 = 0;
	int i_2 = 0;
	while (cur1)
	{
		number1[i_1] = cur1->val;
		cur1 = cur1->next;
		i_1++;
	}
	while (cur2) {
		number2[i_2] = cur2->val;
		i_2++;
		cur2 = cur2->next;
	}
	if (count_1 > count_2)
	{
		int i = 0;
		for (i = 0; i < count_1; i++)
		{
			if (count_1 - i == count_2)
			{
				break;
			}
		}
		int j = 0;
		for (j = 0; j < count_2; j++)
		{
			number1[i] += number2[j];
			i++;
		}
		i = count_1 - 1;
		for (i = count_1 - 1; i > 0; i--) {
			if (number1[i] > 9)
			{
				number1[i - 1] += 1;
				number1[i] %= 10;
			}
		}
		if (number1[0] > 9)
		{
			struct ListNode* head = (struct ListNode*)malloc(sizeof(struct ListNode));
			head->next = l1;
			l1 = head;
			cur1 = l1;
			cur1->val = number1[0] / 10;
			cur1 = cur1->next;
			cur1->val = number1[0] % 10;
			cur1 = cur1->next;
			for (i = 1; i < count_1; i++)
			{
				cur1->val = number1[i];
				cur1 = cur1->next;
			}
			return l1;
		}
		else {
			cur1 = l1;
			for (i = 0; i < count_1; i++)
			{
				cur1->val = number1[i];
				cur1 = cur1->next;
			}
			return l1;
		}
	}
	else {
		int i = 0;
		for (i = 0; i < count_2; i++)
		{
			if (count_2 - i == count_1)
			{
				break;
			}
		}
		int j = 0;
		for (j = 0; j < count_1; j++)
		{
			number2[i] += number1[j];
			i++;
		}
		i = count_2 - 1;
		for (i = count_2 - 1; i > 0; i--)
		{
			if (number2[i] > 9)
			{
				number2[i - 1] += 1;
				number2[i] %= 10;
			}
		}
		if (number2[0] > 9)
		{
			struct ListNode* head = (struct ListNode*)malloc(sizeof(struct ListNode));
			head->next = l2;
			l2 = head;
			cur2 = l2;
			cur2->val = number2[0] / 10;
			cur2 = cur2->next;
			cur2->val = number2[0] % 10;
			cur2 = cur2->next;
			for (i = 1; i < count_2; i++)
			{
				cur2->val = number2[i];
				cur2 = cur2->next;
			}
			return l2;
		}
		else {
			cur2 = l2;
			for (i = 0; i < count_2; i++)
			{
				cur2->val = number2[i];
				cur2 = cur2->next;
			}
			return l2;
		}
	}
}
//??????????????
int findClosestNumber(int* nums, int numsSize) {
	int* number = (int*)malloc(sizeof(int) * numsSize);
	int f = 0;
	int i = 0;
	for (i = 0; i < numsSize; i++) {
		number[f] = abs(nums[i] - 0);
		f++;
	}
	int min = number[0];
	for (i = 1; i < f; i++)
	{
		if (number[i] < min)
		{
			min = number[i];
		}
	}
	int count = 0;
	for (i = 0; i < f; i++)
	{
		if (min == number[i])
		{
			count++;
		}
	}
	int* number1 = (int*)malloc(sizeof(int) * count);
	int l = 0;
	for (i = 0; i < f; i++)
	{
		if (min == number[i]) {
			number1[l] = nums[i];
			l++;
		}
	}
	int max = number1[0];
	for (i = 1; i < l; i++)
	{
		if (number1[i] > max) {
			max = number1[i];
		}
	}
	return max;
}
//???????????
int search(int* arr, int col, int target)
{
	int left = 0;
	int right = col - 1;
	while (left <= right) {
		int mid = (left + right) / 2;
		if (target == arr[mid]) {
			return 1;
		}
		else if (arr[mid] < target) {
			left = mid + 1;
		}
		else {
			right = mid - 1;
		}
	}
	return -1;
}
bool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target) {
	int i = 0;
	int col = *matrixColSize;
	for (i = 0; i < matrixSize; i++) {
		int res = search(matrix[i], col, target);
		if (res == 1)
			return true;
	}
	return false;
}
//????????
bool checkPossibility(int* nums, int numsSize) {
	int* number1 = (int*)malloc(sizeof(int) * numsSize * 3);
	int j = 0;
	int count = 0;
	int i = 0;
	for (i = 0; i < numsSize - 1; i++)
	{
		if (nums[i] > nums[i + 1])
		{
			number1[j] = i;
			j++;
			number1[j] = i + 1;
			j++;
		}
	}
	if (j > 2) {
		return false;
	}
	else {
		if (numsSize - 1 == 0) {
			return true;
		}
		int* number2 = (int*)malloc(sizeof(int) * numsSize);
		int i_1 = 0;
		int f = number1[0];
		int flag = 1;
		for (i = 0; i < numsSize; i++)
		{
			if (i == f)
			{
				continue;
			}
			number2[i_1] = nums[i];
			i_1++;
		}
		for (i = 0; i < i_1 - 1; i++)
		{
			if (number2[i] > number2[i + 1]) {
				flag = 0;
				break;
			}
		}
		int flag1 = 1;
		i_1 = 0;
		f = number1[1];
		for (i = 0; i < numsSize; i++)
		{
			if (i == f)
			{
				continue;
			}
			number2[i_1] = nums[i];
			i_1++;
		}
		for (i = 0; i < i_1 - 1; i++)
		{
			if (number2[i] > number2[i + 1]) {
				flag1 = 0;
				break;
			}
		}
		if (flag == 1 || flag1 == 1) {
			return true;
		}
		else {
			return false;
		}
	}
}
//?????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* sortArrayByParity(int* nums, int numsSize, int* returnSize) {
	int* number = (int*)malloc(sizeof(int) * numsSize);
	int count1 = 0;
	int i = 0;
	for (i = 0; i < numsSize; i++)
	{
		if (nums[i] % 2 == 0) {
			count1++;
		}
	}
	int count2 = 0;
	for (i = 0; i < numsSize; i++)
	{
		if (nums[i] % 2 != 0)
		{
			count2++;
		}
	}
	int* number1 = (int*)malloc(sizeof(int) * count1);
	int* number2 = (int*)malloc(sizeof(int) * count2);
	int j_1 = 0;
	int j_2 = 0;
	for (i = 0; i < numsSize; i++) {
		if (nums[i] % 2 == 0) {
			number1[j_1] = nums[i];
			j_1++;
		}
		else {
			number2[j_2] = nums[i];
			j_2++;
		}
	}
	int j = 0;
	i = 0;
	while (j < j_1) {
		number[i] = number1[j];
		j++;
		i++;
	}
	j = 0;
	while (j < j_2) {
		number[i] = number2[j];
		j++;
		i++;
	}
	*returnSize = numsSize;
	return number;
}
//????????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
void deleteNode(struct ListNode* node) {
	struct ListNode* next = node->next;
	node->val = next->val;
	node->next = next->next;
	free(next);
	next == NULL;
}
//??????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
void preorder(struct TreeNode* root, int* number, int* length) {
	if (root == NULL) {
		return;
	}
	number[(*length)++] = root->val;
	preorder(root->left, number, length);
	preorder(root->right, number, length);
}
void insert_tail(struct TreeNode** root, int data) {
	(*root)->val = data;
	(*root)->left = NULL;
	if ((*root)->right != NULL) {
		*root = (*root)->right;
	}
	else {
		struct TreeNode* newnode = (struct TreeNode*)malloc(sizeof(struct TreeNode));
		newnode->left = NULL;
		newnode->right = NULL;
		(*root)->right = newnode;
		(*root) = newnode;
	}
}
void flatten(struct TreeNode* root) {
	if (root == NULL) {
		return;
	}
	int* number = (int*)malloc(sizeof(int) * 2000);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	preorder(root, number, length);
	int i = 0;
	for (i = 0; i < *length; i++)
	{
		printf("%d ", number[i]);
	}
	printf("\n");
	for (i = 0; i < *length - 1; i++) {
		insert_tail(&root, number[i]);
	}
	struct TreeNode* tail = root;
	while (tail->right != NULL) {
		tail = tail->right;
	}
	tail->val = number[*length - 1];
}
//???????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
typedef struct queue {
	struct TreeNode* data;
	struct queue* next;
}queue_t;
void insert_tail(queue_t** head, struct TreeNode* data)
{
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	memset(newnode, 0, sizeof(queue_t));
	newnode->data = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* cur = *head;
	while (cur->next != NULL) {
		cur = cur->next;
	}
	cur->next = newnode;
}
struct TreeNode* pop(queue_t** head) {
	if (*head == NULL) {
		struct TreeNode* x = (*head)->data;
		(*head) = (*head)->next;
		return x;
	}
	struct TreeNode* x = (*head)->data;
	(*head) = (*head)->next;
	return x;
}
void preorder(struct TreeNode* root, int* length) {
	if (root == NULL) {
		return;
	}
	(*length)++;
	preorder(root->left, length);
	preorder(root->right, length);
}
int deepestLeavesSum(struct TreeNode* root) {
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	preorder(root, length);
	int* treeval = (int*)malloc(sizeof(int) * (*length));
	int j = 0;
	int* col = (int*)malloc(sizeof(int) * (*length + 1));
	int j_1 = 0;
	int count = 1;
	col[j_1] = count;
	j_1++;
	int i = 0;
	int nextcount = 0;
	queue_t* quence = NULL;
	int size = 0;
	insert_tail(&quence, root);
	size++;
	while (size != 0) {
		for (i = 0; i < count; i++) {
			struct TreeNode* node = pop(&quence);
			treeval[j] = node->val;
			j++;
			size--;
			if (node->left != NULL) {
				insert_tail(&quence, node->left);
				size++;
				nextcount++;
			}
			if (node->right != NULL) {
				insert_tail(&quence, node->right);
				size++;
				nextcount++;
			}
		}
		col[j_1] = nextcount;
		j_1++;
		count = nextcount;
		nextcount = 0;
	}
	int count1 = col[j_1 - 2];
	int sum = 0;
	int f = 0;
	for (i = j - 1; i >= 0; i--) {
		sum += treeval[i];
		f++;
		if (f == count1) {
			break;
		}
	}
	return sum;
}
//??????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */


 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
void preorder(struct TreeNode* root, int* number, int* length) {
	if (root == NULL) {
		return;
	}
	number[(*length)++] = root->val;
	preorder(root->left, number, length);
	preorder(root->right, number, length);
}
int compare(const void* a, const void* b) {
	return (*(int*)a - *(int*)b);
}
int* getAllElements(struct TreeNode* root1, struct TreeNode* root2, int* returnSize) {
	int* number = (int*)malloc(sizeof(int) * 10000);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	preorder(root1, number, length);
	preorder(root2, number, length);
	*returnSize = *length;
	qsort(number, *length, sizeof(int), compare);
	return number;
}
//????????
int findDuplicate(int* nums, int numsSize) {
	int* number = (int*)malloc(sizeof(int) * (numsSize + 1));
	int i = 0;
	for (i = 0; i < numsSize + 1; i++) {
		number[i] = 0;
	}
	int f = 0;
	for (i = 0; i < numsSize; i++)
	{
		f = nums[i] % numsSize;
		if (number[f] != 0) {
			return nums[i];
		}
		else {
			number[f] = nums[i];
		}
	}
	return -1;
}
//??????????????????????? 
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
void struct_bst(struct TreeNode** root, int data) {
	struct TreeNode* newnode = (struct TreeNode*)malloc(sizeof(struct TreeNode));
	newnode->val = data;
	newnode->left = NULL;
	newnode->right = NULL;
	if (*root == NULL) {
		*root = newnode;
		return;
	}
	else {
		if (newnode->val > (*root)->val)
		{
			struct_bst(&((*root)->right), newnode->val);
		}
		else {
			struct_bst(&((*root)->left), newnode->val);
		}
	}
}
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize) {
	int i = 0;
	struct TreeNode* root = NULL;
	for (i = 0; i < preorderSize; i++) {
		struct_bst(&root, preorder[i]);
	}
	return root;
}
//?????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
typedef struct queue {
	struct TreeNode* data;
	struct queue* next;
}queue_t;
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->data = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->data;
	*head = (*head)->next;
	return x;
}
double* averageOfLevels(struct TreeNode* root, int* returnSize) {
	double* number = (double*)malloc(sizeof(double) * 1000);
	double sum = 0.0;
	int j = 0;
	int depth = 0;
	int count = 1;
	int nextcount = 0;
	int i = 0;
	int size = 0;
	queue_t* quence = NULL;
	push(&quence, root);
	size++;
	while (size != 0) {
		depth++;
		for (i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&quence);
			size--;
			sum += temp->val;
			if (temp->left != NULL) {
				push(&quence, temp->left);
				size++;
				nextcount++;
			}
			if (temp->right != NULL) {
				push(&quence, temp->right);
				size++;
				nextcount++;
			}
		}
		number[j] = sum * 1.0 / count;
		j++;
		sum = 0.0;
		count = nextcount;
		nextcount = 0;
	}
	*returnSize = j;
	return number;
}
//???????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
typedef struct queue {
	struct TreeNode* data;
	struct queue* next;
}queue_t;
void insert_tail(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->data = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->data;
	*head = (*head)->next;
	return x;
}
int* largestValues(struct TreeNode* root, int* returnSize) {
	if (root == NULL) {
		*returnSize = 0;
		return NULL;
	}
	int max1 = 0;
	int* max = (int*)malloc(sizeof(int) * 1000);
	int j = 0;
	int nextcount = 0;
	int count = 1;
	int size = 0;
	queue_t* sequence = NULL;
	insert_tail(&sequence, root);
	size++;
	int flag = 1;
	while (size != 0) {
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&sequence);
			size--;
			if (flag == 1) {
				max1 = temp->val;
				flag = 0;
			}
			else if (flag == 0) {
				if (temp->val > max1) {
					max1 = temp->val;
				}
			}
			if (temp->left != NULL) {
				insert_tail(&sequence, temp->left);
				size++;
				nextcount++;
			}
			if (temp->right != NULL) {
				insert_tail(&sequence, temp->right);
				size++;
				nextcount++;
			}
		}
		count = nextcount;
		nextcount = 0;
		max[j] = max1;
		j++;
		flag = 1;
		max1 = 0;
	}
	*returnSize = j;
	return max;
}
//??????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
typedef struct queue {
	struct  TreeNode* data;
	struct  queue* next;
}queue_t;
void push(queue_t** head, struct TreeNode* root) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->data = root;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->data;
	(*head) = (*head)->next;
	return x;
}
int maxLevelSum(struct TreeNode* root) {
	int count = 1;
	int nextcount = 0;
	int sum = 0;
	int* sumlevel = (int*)malloc(sizeof(int) * 1000);
	int j = 0;
	int size = 0;
	int i = 0;
	queue_t* enquence = NULL;
	push(&enquence, root);
	size++;
	while (size != 0) {
		for (i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&enquence);
			sum += temp->val;
			size--;
			if (temp->left != NULL) {
				push(&enquence, temp->left);
				nextcount++;
				size++;
			}
			if (temp->right != NULL) {
				push(&enquence, temp->right);
				nextcount++;
				size++;
			}
		}
		count = nextcount;
		sumlevel[j] = sum;
		j++;
		nextcount = 0;
		sum = 0;
	}
	int max = 0;
	for (i = 1; i < j; i++) {
		if (sumlevel[i] > sumlevel[max]) {
			max = i;
		}
	}
	return max + 1;
}
//???????????????
int minSubArrayLen(int target, int* nums, int numsSize) {
	int* number = (int*)malloc(sizeof(int) * 100000);
	int f = 0;
	int i = 0;
	int j = 0;
	int sum = 0;
	for (j = 0; j < numsSize; j++) {
		sum += nums[j];
		if (sum >= target) {
			number[f] = j - i + 1;
			f++;
			int i_1 = i;
			while (sum - nums[i] >= target) {
				sum -= nums[i];
				i++;
			}
			if (i_1 != i) {
				number[f] = j - i + 1;
				f++;
			}
		}
	}
	int min = number[0];
	if (f == 0) {
		return 0;
	}
	else {
		for (i = 0; i < f; i++) {
			printf("%d ", number[i]);
		}
		for (i = 1; i < f; i++) {
			if (number[i] < min) {
				min = number[i];
			}
		}
		return min;
	}
}
//?????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */
typedef struct queue {
	struct TreeNode* data;
	struct queue* next;
}queue_t;
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->data = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->data;
	(*head) = (*head)->next;
	return x;
}
int* rightSideView(struct TreeNode* root, int* returnSize) {
	if (root == NULL) {
		*returnSize = 0;
		return NULL;
	}
	queue_t* enquence = NULL;
	int count = 1;
	int nextcount = 0;
	int size = 0;
	int j = 0;
	int* rightval = (int*)malloc(sizeof(int) * 100);
	push(&enquence, root);
	size++;
	while (size != 0) {
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&enquence);
			size--;
			if (i == count - 1) {
				rightval[j] = temp->val;
				j++;
			}
			if (temp->left != NULL) {
				push(&enquence, temp->left);
				nextcount++;
				size++;
			}
			if (temp->right != NULL) {
				push(&enquence, temp->right);
				nextcount++;
				size++;
			}
		}
		count = nextcount;
		nextcount = 0;
	}
	*returnSize = j;
	return rightval;
}
//????????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

void preorder(struct TreeNode* root, int* number, int* length) {
	if (root == NULL) {
		return;
	}
	number[(*length)++] = root->val;
	preorder(root->left, number, length);
	preorder(root->right, number, length);
}
bool checkTree(struct TreeNode* root) {
	int* length = (int*)malloc(sizeof(int));
	int* number = (int*)malloc(sizeof(int) * 3);
	*length = 0;
	preorder(root, number, length);
	if (number[0] == number[1] + number[2]) {
		return true;
	}
	else {
		return false;
	}
}
//?????????????????:
int countNegatives(int** grid, int gridSize, int* gridColSize) {
	int count = 0;
	int i = 0;
	int j = 0;
	for (i = 0; i < gridSize; i++) {
		for (j = 0; j < *gridColSize; j++) {
			if (grid[i][j] < 0) {
				count++;
			}
		}
	}
	return count;
}
//????????
int hammingDistance(int x, int y) {
	int x_1 = x;
	int count_x = 0;
	while (x_1) {
		count_x++;
		x_1 /= 2;
	}
	int y_1 = y;
	int count_y = 0;
	while (y_1) {
		count_y++;
		y_1 /= 2;
	}
	if (count_x > count_y) {
		int* number_x = (int*)malloc(sizeof(int) * count_x);
		int* number_y = (int*)malloc(sizeof(int) * count_x);
		int j_x = count_x - 1;
		int j_y = count_x - 1;
		while (j_x >= 0) {
			number_x[j_x] = x % 2;
			j_x--;
			x /= 2;
		}
		while (j_y >= 0) {
			number_y[j_y] = y % 2;
			j_y--;
			y /= 2;
		}
		int diff = 0;
		for (int i = 0; i < count_x; i++) {
			if (number_x[i] != number_y[i]) {
				diff++;
			}
		}
		return diff;
	}
	else {
		int* number_x = (int*)malloc(sizeof(int) * count_y);
		int* number_y = (int*)malloc(sizeof(int) * count_y);
		int j_x = count_y - 1;
		int j_y = count_y - 1;
		while (j_x >= 0) {
			number_x[j_x] = x % 2;
			j_x--;
			x /= 2;
		}
		while (j_y >= 0) {
			number_y[j_y] = y % 2;
			j_y--;
			y /= 2;
		}
		int diff = 0;
		for (int i = 0; i < count_y; i++) {
			if (number_x[i] != number_y[i]) {
				diff++;
			}
		}
		return diff;
	}
}
//????????????????
int numberOfSpecialChars(char* word) {
	int* big = (int*)malloc(sizeof(int) * 26);
	memset(big, -1, sizeof(int) * 26);
	int* small = (int*)malloc(sizeof(int) * 26);
	memset(small, -1, sizeof(int) * 26);
	int i = 0;
	for (i = 0; i < strlen(word); i++) {
		if (word[i] >= 'A' && word[i] <= 'Z') {
			int hashindex = word[i] - 'A';
			big[hashindex] = i;
		}
	}
	for (i = 0; i < strlen(word); i++) {
		if (word[i] >= 'a' && word[i] <= 'z') {
			int hashindex = word[i] - 'a';
			small[hashindex] = i;
		}
	}
	int count = 0;
	for (i = 0; i < 26; i++) {
		if (big[i] != -1 && small[i] != -1) {
			count++;
		}
	}
	return count;
}
//?????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Return an array of arrays of size *returnSize.
  * The sizes of the arrays are returned as *returnColumnSizes array.
  * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
  */
typedef struct queue {
	struct TreeNode* data;
	struct queue* next;
}queue_t;
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->data = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->data;
	(*head) = (*head)->next;
	return x;

}
int** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes) {
	*returnSize = 0;
	if (root == NULL) {
		return NULL;
	}
	int count = 1;
	int nextcount = 0;
	int depth = 0;
	queue_t* enquence = NULL;
	int size = 0;
	int* number = (int*)malloc(sizeof(int) * 2000);
	int j = 0;
	int* one_line_count = (int*)malloc(sizeof(int) * 2000);
	int j_1 = 0;
	push(&enquence, root);
	size++;
	while (size != 0) {
		depth++;
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&enquence);
			number[j] = temp->val;
			j++;
			size--;
			if (temp->left != NULL) {
				push(&enquence, temp->left);
				nextcount++;
				size++;
			}
			if (temp->right != NULL) {
				push(&enquence, temp->right);
				nextcount++;
				size++;
			}
		}
		one_line_count[j_1] = count;
		j_1++;
		count = nextcount;
		nextcount = 0;;
	}
	int** node = (int**)malloc(sizeof(int*) * j_1);
	for (int i = 0; i < j_1; i++) {
		node[i] = (int*)malloc(sizeof(int) * one_line_count[i]);
	}
	int f = 0;
	for (int i = 0; i < j_1; i++)
	{
		for (int j = 0; j < one_line_count[i]; j++) {
			node[i][j] = number[f];
			f++;
		}
	}
	for (int i = 0; i < j_1; i++) {
		for (int j = 0; j < one_line_count[i]; j++) {
			printf("%d ", node[i][j]);
		}
		printf("\n");
	}
	*returnSize = j_1;
	*returnColumnSizes = (int*)malloc((*returnSize) * sizeof(int));
	for (int i = 0; i < (*returnSize); i++) {
		(*returnColumnSizes)[i] = one_line_count[i];
	}
	return node;
}
//??????????||
//????????????????????????????????
int compute(char* ret, int length) {
	int i = 0;
	int j = 0;
	int count = 0;
	int value = 0;
	int arr[40] = { 0 };
	int index[40] = { 0 };
	int f_1 = 0;
	int f = 0;
	while (j < length) {
		if (ret[j] != '*' && ret[j] != '/' && j < length) {
			j++;
			count++;
			if (j == length) {
				while (i < j) {
					value += ((ret[i] - '0') * (int)pow(10, count - 1));
					i++;
					count--;
				}
				arr[f] = value;
				f++;
			}
		}
		else {
			if (ret[j] == '*') {
				index[f_1] = -1;
				f_1++;
			}
			else if (ret[j] == '/') {
				index[f_1] = -2;
				f_1++;
			}
			while (i < j) {
				value += ((ret[i] - '0') * (int)pow(10, count - 1));
				i++;
				count--;
			}
			arr[f] = value;
			f++;
			value = 0;
			j++;
			i = j;
			count = 0;
		}
	}
	if (f == 1) {
		return arr[0];
	}
	else {
		int index_t = index[0];
		if (index_t == -1) {
			value = arr[0] * arr[1];
		}
		else {
			value = arr[0] / arr[1];
		}
		int h = 2;
		for (i = 1; i < f_1; i++) {
			if (index[i] == -1) {
				value *= arr[h];
				h++;
			}
			else {
				value /= arr[h];
				h++;
			}
		}
		return value;
	}
}
int calculate(char* s) {
	char* eli_blank_cal = (char*)malloc(sizeof(char) * (strlen(s) + 1));
	int j = 0;
	int i = 0;
	//????????????
	for (i = 0; i < strlen(s); i++) {
		if (s[i] != ' ') {
			eli_blank_cal[j] = s[i];
			j++;
		}
	}
	eli_blank_cal[j] = '\0';
	int k = j;
	int* number = (int*)malloc(sizeof(int) * strlen(eli_blank_cal));
	j = 0;
	int* index = (int*)malloc(sizeof(int) * strlen(eli_blank_cal));
	int f = 0;
	for (i = 0; i < k; i++) {
		if (eli_blank_cal[i] == '+') {
			index[f] = -1;
			f++;
		}
		else if (eli_blank_cal[i] == '-') {
			index[f] = -2;
			f++;
		}
	}
	char* ret = strtok(eli_blank_cal, "+-");
	while (ret != NULL) {
		int value = compute(ret, strlen(ret));
		number[j] = value;
		j++;
		ret = strtok(NULL, "+-");
	}

	if (j == 1) {
		return number[0];
	}
	else {
		int index_t = index[0];
		int value = 0;
		if (index_t == -1) {
			value = number[0] + number[1];
		}
		else if (index_t == -2) {
			value = number[0] - number[1];
		}
		int h = 2;
		for (i = 1; i < f; i++) {
			if (index[i] == -1) {
				value += number[h];
				h++;
			}
			else if (index[i] == -2) {
				value -= number[h];
				h++;
			}
		}
		return value;
	}
}
//?????????
void hanota(int* A, int ASize, int* B, int BSize, int** C, int* CSize) {
	*CSize = ASize;
	*C = A;
}
//?????????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* swapNodes(struct ListNode* head, int k) {
	struct ListNode* cur = head;
	int count = 0;
	while (cur) {
		count++;
		cur = cur->next;
	}
	int* number = (int*)malloc(sizeof(int) * count);
	int j = 0;
	cur = head;
	while (cur) {
		number[j] = cur->val;
		j++;
		cur = cur->next;
	}
	int i = 0;
	int index = 0;
	for (i = 0; i < j; i++) {
		if (k == i + 1) {
			index = i;
		}
	}
	int index1 = 0;
	for (i = j - 1; i >= 0; i--) {
		if (j - i == k) {
			index1 = i;
		}
	}
	int temp = number[index];
	number[index] = number[index1];
	number[index1] = temp;
	cur = head;
	i = 0;
	while (cur) {
		cur->val = number[i];
		i++;
		cur = cur->next;
	}
	return head;
}
//???????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* mergeNodes(struct ListNode* head) {
	struct ListNode* cur = head;
	int count = 0;
	//1.???????????????
	while (cur) {
		count++;
		cur = cur->next;
	}
	cur = head;
	//2.?????????????????????????
	int* number = (int*)malloc(sizeof(int) * count);
	int j = 0;
	while (cur) {
		number[j] = cur->val;
		j++;
		cur = cur->next;
	}
	//3.???????????????0??????????
	int* sum_number = (int*)malloc(sizeof(int) * count);
	int f = 0;
	int i = 0;
	int sum = 0;
	//4.????????????0????????sum_number??????
	for (i = 1; i < j - 1; i++) {
		if (number[i + 1] != 0) {
			sum += number[i];
		}
		else {
			sum += number[i];
			sum_number[f] = sum;
			f++;
			sum = 0;
			i++;
		}
	}
	cur = head;
	i = 0;
	//5.??sum_number????????????
	while (cur) {
		cur->val = sum_number[i];
		i++;
		if (i == f) {
			break;
		}
		cur = cur->next;
	}
	//6.???????????????????????
	cur->next = NULL;
	return head;
}
//????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* deleteMiddle(struct ListNode* head) {
	struct ListNode* cur = head;
	int count = 0;
	while (cur) {
		count++;
		cur = cur->next;
	}
	if (count == 1) {
		return NULL;
	}
	else {
		int* number = (int*)malloc(sizeof(int) * count);
		int i = -1;
		int f = 0;
		cur = head;
		while (cur) {
			i++;
			if (i != count / 2) {
				number[f] = cur->val;
				f++;
			}
			cur = cur->next;
		}
		cur = head;
		i = 0;
		while (cur) {
			cur->val = number[i];
			i++;
			if (i == f) {
				break;
			}
			cur = cur->next;
		}
		cur->next = NULL;
		return head;
	}
}
//?????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 //???????????
typedef struct queue {
	struct TreeNode* value;
	struct queue* next;
}queue_t;
//???
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->value = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
//????
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->value;
	(*head) = (*head)->next;
	return x;
}
//???????
void reverse(int* number, int left, int right) {
	while (left <= right) {
		int temp = number[left];
		number[left] = number[right];
		number[right] = temp;
		left++;
		right--;
	}
}
struct TreeNode* reverseOddLevels(struct TreeNode* root) {
	queue_t* quence = NULL;
	int nextcount = 0;
	int count = 1;
	int depth = -1;
	int* number = (int*)malloc(sizeof(int) * 20000);//?????????????
	int j = 0;
	int index = 0;//???????????????
	int size = 0;
	//??????????
	push(&quence, root);
	size++;
	while (size != 0) {
		depth++;
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&quence);
			number[j] = temp->val;//???????????????????????
			j++;
			size--;
			if (temp->left != NULL) {
				push(&quence, temp->left);
				size++;
				nextcount++;
			}
			if (temp->right != NULL) {
				push(&quence, temp->right);
				size++;
				nextcount++;
			}
		}
		//???????????,?????????????????????????????????????????
		if (depth % 2 == 0) {
			index += count;
		}
		else {
			reverse(number, index, j - 1);//?????????????????????????????
			index += count;
		}
		//????????????????count;
		count = nextcount;
		nextcount = 0;
	}
	size = 0;
	int i = 0;
	push(&quence, root);
	size++;
	//???????????????????????????????????
	while (size != 0) {
		struct TreeNode* temp = pop(&quence);
		size--;
		temp->val = number[i];
		i++;
		if (temp->left != NULL) {
			push(&quence, temp->left);
			size++;
		}
		if (temp->right != NULL) {
			push(&quence, temp->right);
			size++;
		}
	}
	return root;
}
//??????????????||
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Return an array of arrays of size *returnSize.
  * The sizes of the arrays are returned as *returnColumnSizes array.
  * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
  */
  //????????
typedef struct queue {
	struct TreeNode* value;
	struct queue* next;
}queue_t;
//???
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->value = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
//????
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->value;
	(*head) = (*head)->next;
	return x;
}
void reverse(int* number, int rows) {
	int left = 0;
	int right = rows - 1;
	while (left <= right) {
		int temp = number[left];
		number[left] = number[right];
		number[right] = temp;
		left++;
		right--;
	}
}
int** levelOrderBottom(struct TreeNode* root, int* returnSize, int** returnColumnSizes) {
	*returnSize = 0;
	if (root == NULL) {
		return NULL;
	}
	int* each_line_nodes = (int*)malloc(sizeof(int) * 2000);//??????????
	int j_1 = 0;
	int* level_order_number = (int*)malloc(sizeof(int) * 2000);//?????????????
	int j_2 = 0;
	int depth = 0;//??????
	int count = 1;//?????????
	int nextcount = 0;//????????????
	int size = 0;//?????????????
	queue_t* quence = NULL;//???????
	//??????????
	push(&quence, root);
	size++;
	while (size != 0) {
		depth++;
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&quence);
			size--;
			level_order_number[j_2] = temp->val;
			j_2++;
			if (temp->left != NULL) {
				push(&quence, temp->left);
				size++;
				nextcount++;
			}
			if (temp->right != NULL) {
				push(&quence, temp->right);
				size++;
				nextcount++;
			}
		}
		each_line_nodes[j_1] = count;
		j_1++;
		count = nextcount;
		nextcount = 0;
	}
	//???????????
	int** array = (int**)malloc(sizeof(int*) * depth);
	//????????????????????
	reverse(each_line_nodes, j_1);
	for (int i = 0; i < depth; i++) {
		array[i] = (int*)malloc(sizeof(int) * each_line_nodes[i]);
	}
	int f = j_2 - 1;
	//??????????????????????????
	for (int i = 0; i < depth; i++) {
		for (int j = 0; j < each_line_nodes[i]; j++) {
			array[i][j] = level_order_number[f];
			f--;
		}
	}
	//?????????????????
	for (int i = 0; i < depth; i++) {
		reverse(array[i], each_line_nodes[i]);
	}
	*returnSize = depth;
	*returnColumnSizes = (int*)malloc(sizeof(int) * (*returnSize));
	for (int i = 0; i < depth; i++) {
		(*returnColumnSizes)[i] = each_line_nodes[i];
	}
	return array;
}
//????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 //????????
typedef struct queue {
	struct TreeNode* data;
	struct queue* next;
}queue_t;
//???
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->data = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
//????
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->data;
	(*head) = (*head)->next;
	return x;
}
bool isCompleteTree(struct TreeNode* root) {
	int node_count = 0;//?????????
	int* level_travel_node = (int*)malloc(sizeof(int) * 200);//????????????????
	int j = 0;
	int depth = 0;
	queue_t* quence = NULL;
	int count = 1;
	int nextcount = 0;
	int size = 0;
	//??????????
	push(&quence, root);
	size++;
	node_count++;
	while (size != 0) {
		depth++;
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&quence);
			size--;
			if (temp->left != NULL) {
				push(&quence, temp->left);
				size++;
				node_count++;
				nextcount++;
			}
			if (temp->right != NULL) {
				push(&quence, temp->right);
				size++;
				node_count++;
				nextcount++;
			}
		}
		count = nextcount;
		nextcount = 0;
	}
	//??????????????????1??????????true
	if (node_count == 1) {
		return true;
	}
	else {
		//???????????1???????????????????????????????????????????????false
		if (node_count >= (int)pow(2, depth - 1) && node_count <= ((int)pow(2, depth) - 1)) {
			printf("%d ", node_count);
			int depth_t = 0;
			size = 0;
			count = 1;
			int remove_line_count = 0;//??????????????????
			nextcount = 0;
			push(&quence, root);
			size++;
			remove_line_count++;
			//??ǎ???????????????????????????????
			while (size != 0) {
				depth_t++;
				//???????????????? 
				if (depth_t != depth - 1) {
					for (int i = 0; i < count; i++) {
						struct TreeNode* temp = pop(&quence);
						size--;
						if (temp->left != NULL) {
							push(&quence, temp->left);
							size++;
							remove_line_count++;
							nextcount++;
						}
						if (temp->right != NULL) {
							push(&quence, temp->right);
							size++;
							remove_line_count++;
							nextcount++;
						}
					}
					count = nextcount;
					nextcount = 0;
				}
				else {
					//????????????????????????????????????-1????????1
					for (int i = 0; i < count; i++) {
						struct TreeNode* temp = pop(&quence);
						size--;
						if (temp->left != NULL) {
							level_travel_node[j] = 1;
							j++;
						}
						else {
							level_travel_node[j] = -1;
							j++;
						}
						if (temp->right != NULL) {
							level_travel_node[j] = 1;
							j++;
						}
						else {
							level_travel_node[j] = -1;
							j++;
						}
					}
					break;
				}
			}
			//???????????????????????????????false
			if (remove_line_count != ((int)pow(2, depth - 1) - 1)) {
				return false;
			}
			else {
				int i = 0;
				for (i = 0; i < j; i++) {
					if (level_travel_node[i] == -1) {
						break;
					}
				}
				//???-1???????1??????????????????true
				int j_1 = i + 1;
				for (j_1 = i + 1; j_1 < j; j_1++) {
					if (level_travel_node[j_1] == 1) {
						return false;
					}
				}
				return true;
			}

		}
		else {
			return false;
		}
	}
}
//???????????????????????
/**
 * Definition for a Node.
 * struct Node {
 *     int val;
 *     struct Node *left;
 *     struct Node *right;
 *     struct Node *next;
 * };
 */
 //???????????
typedef struct queue {
	struct TreeNode* value;
	struct queue* next1;
}queue_t;
//???
void push(queue_t** head, struct Node* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->value = data;
	newnode->next1 = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next1 != NULL) {
		tail = tail->next1;
	}
	tail->next1 = newnode;
}
//????
struct Node* pop(queue_t** head) {
	struct TreeNode* x = (*head)->value;
	(*head) = (*head)->next1;
	return x;
}
struct Node* connect(struct Node* root) {
	if (root == NULL) {
		return NULL;
	}
	int count = 1;
	int nextcount = 0;
	int size = 0;
	queue_t* quence = NULL;
	push(&quence, root);
	size++;
	//??????????
	while (size != 0) {
		for (int i = 0; i < count; i++) {
			struct Node* temp = pop(&quence);
			size--;
			if (i == count - 1) {
				temp->next = NULL;
			}
			else {
				temp->next = quence->value;
			}
			if (temp->left != NULL) {
				push(&quence, temp->left);
				size++;
				nextcount++;
			}
			if (temp->right != NULL) {
				push(&quence, temp->right);
				size++;
				nextcount++;
			}
		}
		count = nextcount;
		nextcount = 0;
	}
	return root;
}
//???????????????????????||
/**
 * Definition for a Node.
 * struct Node {
 *     int val;
 *     struct Node *left;
 *     struct Node *right;
 *     struct Node *next;
 * };
 */
 //???????????
typedef struct queue {
	struct TreeNode* value;
	struct queue* next1;
}queue_t;
//???
void push(queue_t** head, struct Node* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->value = data;
	newnode->next1 = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next1 != NULL) {
		tail = tail->next1;
	}
	tail->next1 = newnode;
}
//????
struct Node* pop(queue_t** head) {
	struct TreeNode* x = (*head)->value;
	(*head) = (*head)->next1;
	return x;
}
struct Node* connect(struct Node* root) {
	if (root == NULL) {
		return NULL;
	}
	int count = 1;
	int nextcount = 0;
	int size = 0;
	queue_t* quence = NULL;
	push(&quence, root);
	size++;
	//??????????
	while (size != 0) {
		for (int i = 0; i < count; i++) {
			struct Node* temp = pop(&quence);
			size--;
			if (i == count - 1) {
				temp->next = NULL;
			}
			else {
				temp->next = quence->value;
			}
			if (temp->left != NULL) {
				push(&quence, temp->left);
				size++;
				nextcount++;
			}
			if (temp->right != NULL) {
				push(&quence, temp->right);
				size++;
				nextcount++;
			}
		}
		count = nextcount;
		nextcount = 0;
	}
	return root;
}
//??????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Return an array of arrays of size *returnSize.
  * The sizes of the arrays are returned as *returnColumnSizes array.
  * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
  */
  //????????
typedef struct queue {
	struct TreeNode* value;
	struct queue* next;
}queue_t;
//???
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->value = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
//????
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->value;
	(*head) = (*head)->next;
	return x;
}
void reverse(int* number, int left, int right) {
	while (left <= right) {
		int temp = number[left];
		number[left] = number[right];
		number[right] = temp;
		left++;
		right--;
	}
}
int** zigzagLevelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes) {
	*returnSize = 0;
	if (root == NULL) {
		return NULL;
	}
	int* each_line_nodes = (int*)malloc(sizeof(int) * 2000);//??????????
	int j_1 = 0;
	int* level_order_number = (int*)malloc(sizeof(int) * 2000);//?????????????
	int j_2 = 0;
	int depth = 0;//??????
	int count = 1;//?????????
	int index = 0;//?????????????????
	int nextcount = 0;//????????????
	int size = 0;//?????????????
	queue_t* quence = NULL;//???????
	//??????????
	push(&quence, root);
	size++;
	while (size != 0) {
		depth++;
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&quence);
			size--;
			level_order_number[j_2] = temp->val;
			j_2++;
			if (temp->left != NULL) {
				push(&quence, temp->left);
				size++;
				nextcount++;
			}
			if (temp->right != NULL) {
				push(&quence, temp->right);
				size++;
				nextcount++;
			}
		}
		each_line_nodes[j_1] = count;
		j_1++;
		if (depth % 2 == 0) {
			reverse(level_order_number, index, j_2 - 1);
			index += count;
		}
		else {
			index += count;
		}
		count = nextcount;
		nextcount = 0;
	}
	//???????????
	int** array = (int**)malloc(sizeof(int*) * depth);
	for (int i = 0; i < depth; i++) {
		array[i] = (int*)malloc(sizeof(int) * each_line_nodes[i]);
	}
	int f = 0;
	for (int i = 0; i < depth; i++) {
		for (int j = 0; j < each_line_nodes[i]; j++) {
			array[i][j] = level_order_number[f];
			f++;
		}
	}
	*returnSize = depth;
	*returnColumnSizes = (int*)malloc(sizeof(int) * (*returnSize));
	for (int i = 0; i < depth; i++) {
		(*returnColumnSizes)[i] = each_line_nodes[i];
	}
	return array;
}
//?????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 //????????
typedef struct queue {
	struct TreeNode* data;
	struct queue* next;
}queue_t;
//???
void push(queue_t** head, struct TreeNode* data) {
	queue_t* newnode = (queue_t*)malloc(sizeof(queue_t));
	newnode->data = data;
	newnode->next = NULL;
	if (*head == NULL) {
		*head = newnode;
		return;
	}
	queue_t* tail = *head;
	while (tail->next != NULL) {
		tail = tail->next;
	}
	tail->next = newnode;
}
//????
struct TreeNode* pop(queue_t** head) {
	struct TreeNode* x = (*head)->data;
	(*head) = (*head)->next;
	return x;

}
//????????
bool even_judge(int* oddnumber, int length) {
	int i = 0;
	for (i = 0; i < length - 1; i++) {
		if (oddnumber[i] >= oddnumber[i + 1]) {
			return false;
		}
		if (oddnumber[i] % 2 == 0) {
			return false;
		}
	}
	if (oddnumber[length - 1] % 2 == 0) {
		return false;
	}
	return true;
}
//?????????
bool odd_judge(int* evennumber, int length) {
	int i = 0;
	for (i = 0; i < length - 1; i++) {
		if (evennumber[i] <= evennumber[i + 1]) {
			return false;
		}
		if (evennumber[i] % 2 != 0) {

			return false;
		}
	}
	if (evennumber[length - 1] % 2 != 0) {
		printf("1\n");
		return false;
	}
	return true;
}
bool isEvenOddTree(struct TreeNode* root) {
	int count = 1;
	int nextcount = 0;
	int depth = 0;
	queue_t* enquence = NULL;
	int size = 0;
	int* number = (int*)malloc(sizeof(int) * 100000);//??????????????
	int j = 0;
	int* one_line_count = (int*)malloc(sizeof(int) * 100000);//????????????
	int j_1 = 0;
	push(&enquence, root);
	size++;
	//??????????
	while (size != 0) {
		depth++;
		for (int i = 0; i < count; i++) {
			struct TreeNode* temp = pop(&enquence);
			number[j] = temp->val;
			j++;
			size--;
			if (temp->left != NULL) {
				push(&enquence, temp->left);
				nextcount++;
				size++;
			}
			if (temp->right != NULL) {
				push(&enquence, temp->right);
				nextcount++;
				size++;
			}
		}
		one_line_count[j_1] = count;
		j_1++;
		count = nextcount;
		nextcount = 0;;
	}
	//???????????
	int** node = (int**)malloc(sizeof(int*) * j_1);
	for (int i = 0; i < j_1; i++) {
		node[i] = (int*)malloc(sizeof(int) * one_line_count[i]);
	}
	int f = 0;
	//??????????
	for (int i = 0; i < j_1; i++)
	{
		for (int j = 0; j < one_line_count[i]; j++) {
			node[i][j] = number[f];
			f++;
		}
	}
	for (int i = 0; i < j_1; i++) {
		if (i % 2 == 0) {
			bool ret = even_judge(node[i], one_line_count[i]);
			if (ret == false) {
				return false;
			}
		}
		else {
			bool ret = odd_judge(node[i], one_line_count[i]);
			if (ret == false) {
				return false;
			}
		}
	}
	return true;
}
//??????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* rearrangeArray(int* nums, int numsSize, int* returnSize) {
	int* ne_int = (int*)malloc(sizeof(int) * (numsSize / 2));//??????????
	memset(ne_int, 0, sizeof(int) * (numsSize / 2));
	int* po_int = (int*)malloc(sizeof(int) * (numsSize / 2));//??????????
	memset(po_int, 0, sizeof(int) * (numsSize / 2));
	int ne_f = 0;//??????
	int po_f = 0;//??????
	for (int i = 0; i < numsSize; i++) {
		if (nums[i] > 0) {
			po_int[po_f] = nums[i];
			po_f++;
		}
		else {
			ne_int[ne_f] = nums[i];
			ne_f++;
		}
	}
	int* number = (int*)malloc(sizeof(int) * numsSize);
	po_f = 0;
	ne_f = 0;
	for (int i = 0; i < numsSize; i++) {
		if (i % 2 == 0) {
			number[i] = po_int[po_f];
			po_f++;
		}
		else {
			number[i] = ne_int[ne_f];
			ne_f++;
		}
	}
	*returnSize = numsSize;
	return number;
}
//?????k??????????
/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** sortTheStudents(int** score, int scoreSize, int* scoreColSize, int k, int* returnSize, int** returnColumnSizes) {
	int** sort_score = (int**)malloc(sizeof(int*) * scoreSize);
	for (int i = 0; i < scoreSize; i++) {
		sort_score[i] = (int*)malloc(sizeof(int) * (*scoreColSize));
	}
	int n = scoreSize;
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1 - i; j++) {
			if (score[j][k] < score[j + 1][k]) {
				int* temp = (int*)malloc(sizeof(int) * (*scoreColSize));
				memcpy(temp, score[j], sizeof(int) * (*scoreColSize));
				memcpy(score[j], score[j + 1], sizeof(int) * (*scoreColSize));
				memcpy(score[j + 1], temp, sizeof(int) * (*scoreColSize));
			}
		}
	}
	for (int i = 0; i < scoreSize; i++) {
		for (int j = 0; j < *scoreColSize; j++) {
			sort_score[i][j] = score[i][j];
		}
	}
	*returnSize = scoreSize;
	*returnColumnSizes = (int*)malloc(sizeof(int) * (scoreSize));
	for (int i = 0; i < scoreSize; i++) {
		(*returnColumnSizes)[i] = *scoreColSize;
	}
	return sort_score;
}
//???????1???????
/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
 //???????1??0?????
void one_count(int* number, int length, int* o, int* z) {
	int i = 0;
	for (i = 0; i < length; i++) {
		if (number[i] == 1) {
			*o = *o + 1;
		}
		else {
			*z = *z + 1;
		}
	}
}
int** onesMinusZeros(int** grid, int gridSize, int* gridColSize, int* returnSize, int** returnColumnSizes) {
	int* onerow = (int*)malloc(sizeof(int) * gridSize);//?????1?????
	int* zerorow = (int*)malloc(sizeof(int) * gridSize);//?????0?????
	int i1 = 0;
	int* onecol = (int*)malloc(sizeof(int) * (*gridColSize));//?????1?????
	int* zerocol = (int*)malloc(sizeof(int) * (*gridColSize));//?????0?????
	int i2 = 0;
	int o = 0; //1?????????
	int z = 0; //0?????????
	//???????1??0????????? 
	for (int i = 0; i < gridSize; i++) {
		one_count(grid[i], *gridColSize, &o, &z);
		onerow[i1] = o;
		zerorow[i1] = z;
		i1++;
		o = 0;
		z = 0;
	}
	o = 0;
	z = 0;
	//???????1??0?????
	for (int j = 0; j < *gridColSize; j++) {
		for (int i = 0; i < gridSize; i++) {
			if (grid[i][j] == 1) {
				o++;
			}
			else {
				z++;
			}
		}
		onecol[i2] = o;
		zerocol[i2] = z;
		i2++;
		o = 0;
		z = 0;
	}
	// for(int i = 0;i < gridSize;i++){
	//     printf("%d %d\n",onerow[i],zerorow[i]);
	// }
	//??????????
	int** diff = (int**)malloc(sizeof(int*) * (gridSize));
	for (int i = 0; i < gridSize; i++) {
		diff[i] = (int*)malloc(sizeof(int) * (*gridColSize));
	}
	for (int i = 0; i < gridSize; i++) {
		for (int j = 0; j < *gridColSize; j++) {
			diff[i][j] = onerow[i] + onecol[j] - zerorow[i] - zerocol[j];
		}
	}
	*returnSize = gridSize;
	*returnColumnSizes = (int*)malloc(sizeof(int) * (gridSize));
	for (int i = 0; i < gridSize; i++) {
		(*returnColumnSizes)[i] = *gridColSize;
	}
	return diff;
}
//???????????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* occurrencesOfElement(int* nums, int numsSize, int* queries, int queriesSize, int x, int* returnSize) {
	int* k_index = (int*)malloc(sizeof(int) * numsSize);
	int j = 0;
	for (int i = 0; i < numsSize; i++) {
		if (nums[i] == x) {
			k_index[j] = i;
			j++;
		}
	}
	int* index = (int*)malloc(sizeof(int) * queriesSize);
	int i = 0;
	for (i = 0; i < queriesSize; i++) {
		if (queries[i] > j) {
			index[i] = -1;
		}
		else {
			index[i] = k_index[queries[i] - 1];
		}
	}
	*returnSize = queriesSize;
	return index;
}
//????????

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* swapNumbers(int* numbers, int numbersSize, int* returnSize) {
	numbers[0] = numbers[0] ^ numbers[1];
	numbers[1] = numbers[0] ^ numbers[1];
	numbers[0] = numbers[0] ^ numbers[1];
	int* number = (int*)malloc(sizeof(int) * 2);
	number[0] = numbers[0];
	number[1] = numbers[1];
	*returnSize = 2;
	return number;
}
//??????????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* pivotArray(int* nums, int numsSize, int pivot, int* returnSize) {
	int* less_number = (int*)malloc(sizeof(int) * numsSize);//???pivot??????
	int j_1 = 0;
	int* equal_number = (int*)malloc(sizeof(int) * numsSize);//????pivot??????
	int j_2 = 0;
	int* more_number = (int*)malloc(sizeof(int) * numsSize);//????pivot??????
	int j_3 = 0;
	//????nums????,??nums??????????????????????????
	for (int i = 0; i < numsSize; i++) {
		if (nums[i] < pivot) {
			less_number[j_1] = nums[i];
			j_1++;
		}
		else if (nums[i] == pivot) {
			equal_number[j_2] = nums[i];
			j_2++;
		}
		else {
			more_number[j_3] = nums[i];
			j_3++;
		}
	}
	int* number = (int*)malloc(sizeof(int) * numsSize);//??????????????
	int i = 0;
	int f = 0;
	//??????????????????????????number??????
	while (i < j_1) {
		number[f] = less_number[i];
		f++;
		i++;
	}
	i = 0;
	while (i < j_2) {
		number[f] = equal_number[i];
		f++;
		i++;
	}
	i = 0;
	while (i < j_3) {
		number[f] = more_number[i];
		f++;
		i++;
	}
	*returnSize = numsSize;
	return number;
}
//???????????????:
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int judge(int* queries, int* points) {
	double squares = pow(queries[0] - points[0], 2) + pow(queries[1] - points[1], 2);
	double number = sqrt(squares);
	if (number > queries[2]) {
		return -1;
	}
	else {
		return 1;
	}
}
int* countPoints(int** points, int pointsSize, int* pointsColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize) {
	int* number_of_dots = (int*)malloc(sizeof(int) * queriesSize);
	int f = 0;
	for (int i = 0; i < queriesSize; i++) {
		int count = 0;
		for (int j = 0; j < pointsSize; j++) {
			int ret = judge(queries[i], points[j]);
			if (ret == 1) {
				count++;
			}
		}
		number_of_dots[f] = count++;
		f++;
	}
	*returnSize = queriesSize;
	return number_of_dots;
}
//??????????
int triangularSum(int* nums, int numsSize) {
	while (numsSize != 1) {
		for (int i = 0; i < numsSize - 1; i++) {
			nums[i] = (nums[i] + nums[i + 1]) % 10;
		}
		numsSize--;
	}
	return nums[0];
}
//?????????????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int judge(int* A, int* B, int i) {
	int j = 0;
	int count = 0;
	int* number = (int*)malloc(sizeof(int) * 51);
	//??????????????????????
	memset(number, 0, sizeof(int) * 51);
	for (j = 0; j <= i; j++) {
		int index = A[j] - 1;
		number[index] = A[j];
	}
	for (j = 0; j <= i; j++) {
		int index = B[j] - 1;
		if (number[index] != 0) {
			count++;
		}
	}
	return count;
}
int* findThePrefixCommonArray(int* A, int ASize, int* B, int BSize, int* returnSize) {
	int* C = (int*)malloc(sizeof(int) * ASize);//??????????
	int j = 0;
	for (int i = 0; i < ASize; i++) {
		int ret = judge(A, B, i);
		C[j] = ret;
		j++;
	}
	*returnSize = ASize;
	return C;
}
//????????
int compare(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
void sort(int* arr, int length) {
	qsort(arr, length, sizeof(int), compare);
}
int matrixSum(int** nums, int numsSize, int* numsColSize) {
	for (int i = 0; i < numsSize; i++) {
		sort(nums[i], *numsColSize);
	}
	int sum = 0;
	for (int j = 0; j < *numsColSize; j++) {
		int max = nums[0][j];
		for (int i = 1; i < numsSize; i++) {
			if (nums[i][j] > max) {
				max = nums[i][j];
			}
		}
		sum += max;
	}
	return sum;
}
//?????????????????
void one_count(char* string, int* number, int* length) {
	int count = 0;
	for (int i = 0; i < strlen(string); i++) {
		if (string[i] == '1') {
			count++;
		}
	}
	if (count == 0) {
		return;
	}
	else {
		number[(*length)++] = count;
		return;
	}
}
int numberOfBeams(char** bank, int bankSize) {
	int* number = (int*)malloc(sizeof(int) * bankSize);
	int* length = (int*)malloc(sizeof(int));
	*length = 0;
	for (int i = 0; i < bankSize; i++) {
		one_count(bank[i], number, length);
	}
	if (*length == 1)
		return 0;
	else {
		int sum = 0;
		for (int i = 0; i < *length - 1; i++) {
			sum += (number[i] * number[i + 1]);
		}
		return sum;
	}
}
//???????????????????????????


int minOperations(int n) {
	if (n % 2 != 0) {
		n /= 2;
		int f = 2;
		int sum = 0;
		int i = 1;
		while (i <= n) {
			sum += f;
			f += 2;
			i++;
		}
		return sum;
	}
	else {
		n /= 2;
		int sum = 0;
		int i = 1;
		int f = 1;
		while (i <= n) {
			sum += f;
			f += 2;
			i++;
		}
		return sum;
	}
}
//????????????????????????


int minOperations(int n) {
	if (n % 2 != 0) {
		n /= 2;
		int f = 2;
		int sum = 0;
		int i = 1;
		while (i <= n) {
			sum += f;
			f += 2;
			i++;
		}
		return sum;
	}
	else {
		n /= 2;
		int sum = 0;
		int i = 1;
		int f = 1;
		while (i <= n) {
			sum += f;
			f += 2;
			i++;
		}
		return sum;
	}
}
//????????
int compare(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int findValueOfPartition(int* nums, int numsSize) {
	qsort(nums, numsSize, sizeof(int), compare);//??????
	int* number = (int*)malloc(sizeof(int) * numsSize);//???????????
	int j = 0;
	for (int i = 0; i < numsSize - 1; i++) {
		number[j] = nums[i + 1] - nums[i];//???????????????????
		j++;
	}
	//???????????
	int min = number[0];
	for (int i = 1; i < j; i++) {
		if (number[i] < min) {
			min = number[i];
		}
	}
	return min;
}
//??????????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
int pairSum(struct ListNode* head) {
	struct ListNode* cur = head;
	int count = 0;
	//1.?????????????????????
	while (cur) {
		count++;
		cur = cur->next;
	}
	//2.?????????????????
	int* number = (int*)malloc(sizeof(int) * count);
	int j = 0;
	cur = head;
	//3.????????????????????
	while (cur) {
		number[j] = cur->val;
		j++;
		cur = cur->next;
	}
	//4.??????????????????????
	int* sum = (int*)malloc(sizeof(int) * count);
	int f = 0;
	int left = 0;
	int right = count - 1;
	//5.???????Number?????????????????????sum??????
	while (left < right) {
		sum[f] = number[left] + number[right];
		f++;
		left++;
		right--;
	}
	//6.??sum???????????
	int max = sum[0];
	for (int i = 1; i < f; i++) {
		if (sum[i] > max) {
			max = sum[i];
		}
	}
	return max;
}
//????????????????????????????


/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
long long* sumOfThree(long long num, int* returnSize) {
	if (num % 3 != 0) {
		*returnSize = 0;
		return NULL;
	}
	else {
		long long* number = (long long*)malloc(sizeof(long long) * 3);
		long long number1 = num / 3;
		number[0] = number1 - 1;
		number[1] = number1;
		number[2] = number1 + 1;
		*returnSize = 3;
		return number;
	}
}
//?????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int compare(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
bool* checkArithmeticSubarrays(int* nums, int numsSize, int* l, int lSize, int* r, int rSize, int* returnSize) {
	bool* answer = (bool*)malloc(sizeof(int) * lSize);//??????bool????????????????????????????????
	int j = 0;
	for (int i = 0; i < lSize; i++) {
		int arr[500] = { 0 };//?????????????????????????????
		memcpy(arr, nums + l[i], sizeof(int) * (r[i] - l[i] + 1));//?????memcpy,??nums????????????????
		qsort(arr, r[i] - l[i] + 1, sizeof(int), compare);//????????
		int diff[500] = { 0 };//?????????????????????
		int j_1 = 0;
		for (int f = 0; f < (r[i] - l[i]); f++) {
			diff[j_1] = arr[f + 1] - arr[f];
			j_1++;
		}
		int flag = 1;
		//?????????????????????????????????????????
		for (int f = 0; f < j_1 - 1; f++) {
			if (diff[f] != diff[f + 1]) {
				flag = 0;
				break;
			}
		}
		if (flag == 1) {
			answer[j] = true;
			j++;
		}
		else {
			answer[j] = false;
			j++;
		}
	}
	*returnSize = lSize;
	return answer;
}
//????????????????
int reverse(int n) {
	int number = n;
	int count = 0;
	while (number) {
		count++;
		number /= 10;
	}
	number = n;
	int sum = 0;
	while (number) {
		int temp = number % 10;
		sum += (temp * pow(10, count - 1));
		count--;
		number /= 10;
	}
	return sum;
}
int countDistinctIntegers(int* nums, int numsSize) {
	int* number = (int*)malloc(sizeof(int) * numsSize * 2);
	memcpy(number, nums, sizeof(int) * numsSize);
	int j = 0;
	j = numsSize;
	for (int i = 0; i < numsSize; i++) {
		int ret = reverse(nums[i]);
		number[j] = ret;
		j++;
	}
	int* temp = (int*)malloc(sizeof(int) * 1000000);
	memset(temp, 0, sizeof(int) * 1000000);
	for (int i = 0; i < numsSize * 2; i++) {
		int index = number[i] - 1;
		temp[index] = number[i];
	}
	int count = 0;
	for (int i = 0; i < 1000000; i++) {
		if (temp[i] != 0) {
			count++;
		}
	}
	return count;
}
//???????????????????
int compare(const void* a, const void* b) {
	return *(char*)a - *(char*)b;
}
char* sortVowels(char* s) {
	char* temp = (char*)malloc(sizeof(int) * (strlen(s) + 1));
	memset(temp, '\0', sizeof(char) * (strlen(s) + 1));
	int j = 0;
	for (int i = 0; i < strlen(s); i++) {
		if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U' || s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') {
			temp[j] = s[i];
			j++;
		}
	}
	if (j == 0) {
		return s;
	}
	else {
		qsort(temp, j, sizeof(char), compare);
		int f = 0;
		for (int i = 0; i < strlen(s); i++) {
			if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U' || s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') {
				s[i] = temp[f];
				f++;
			}
		}
		return s;
	}
}
//??????????????????
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
long long* findPrefixScore(int* nums, int numsSize, int* returnSize) {
	long long* number = (long long*)malloc(sizeof(long long) * numsSize);
	memset(number, 0, sizeof(long long) * numsSize);
	int j = 0;
	int max = 0;
	for (int i = 0; i < numsSize; i++) {
		if (nums[i] > max) {
			max = nums[i];
		}
		number[j] = max + nums[i];
		j++;
	}
	long long sum = 0;
	for (int i = 0; i < numsSize; i++) {
		sum += number[i];
		number[i] = sum;
	}
	*returnSize = numsSize;
	return number;
}
//?????????
/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** matrixBlockSum(int** mat, int matSize, int* matColSize, int k, int* returnSize, int** returnColumnSizes) {
	int** number = (int**)malloc(sizeof(int*) * matSize);
	for (int i = 0; i < matSize; i++) {
		number[i] = (int*)malloc(sizeof(int) * (*matColSize));
	}
	for (int i = 0; i < matSize; i++) {
		for (int j = 0; j < *matColSize; j++) {
			int r1 = i - k;
			int r2 = i + k;
			int c1 = j - k;
			int c2 = j + k;
			while (r1 < 0) {
				r1++;
			}
			while (r2 > matSize - 1) {
				r2--;
			}
			while (c1 < 0) {
				c1++;
			}
			while (c2 > (*matColSize - 1))
			{
				c2--;
			}
			int sum = 0;
			for (int i1 = r1; i1 <= r2; i1++) {
				for (int j1 = c1; j1 <= c2; j1++) {
					sum += mat[i1][j1];
				}
			}
			number[i][j] = sum;
		}
	}
	*returnSize = matSize;
	*returnColumnSizes = (int*)malloc(sizeof(int) * (matSize));
	for (int i = 0; i < matSize; i++) {
		(*returnColumnSizes)[i] = *matColSize;
	}
	return number;
}
//????????||/**
*Return an array of arrays of size* returnSize.
* The sizes of the arrays are returned as* returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
* /
int** generateMatrix(int n, int* returnSize, int** returnColumnSizes) {
	int** number = (int**)malloc(sizeof(int*) * n);
	int i = 0;
	for (i = 0; i < n; i++) {
		number[i] = (int*)malloc(sizeof(int) * n);
	}
	int row = n;
	i = 0;
	int j = 0;
	int count = 1;
	while (count <= n * n) {
		int i1 = i;
		int j1 = j;
		while (j1 < row) {
			number[i1][j1] = count;
			j1++;
			count++;
		}
		j1--;
		i1++;
		while (i1 < row) {
			number[i1][j1] = count;
			i1++;
			count++;
		}
		i1--;
		j1--;
		while (j1 >= j) {
			number[i1][j1] = count;
			j1--;
			count++;
		}
		j1++;
		i1--;
		while (i1 > i) {
			number[i1][j1] = count;
			i1--;
			count++;
		}
		i++;
		j++;
		row--;
	}
	*returnSize = n;
	*returnColumnSizes = (int*)malloc(sizeof(int) * n);
	for (i = 0; i < *returnSize; i++) {
		(*returnColumnSizes)[i] = n;
	}
	return number;
}
//n???k??????
int kthFactor(int n, int k) {
	int i = 0;
	//???????????????????
	int* number = (int*)malloc(sizeof(int) * 1000);
	int f = 0;
	//??????????????????
	for (int i = 1; i <= n; i++) {
		if (n % i == 0) {
			number[f] = i;
			f++;
		}
	}
	//???k??????????????????
	if (k > f) {
		return -1;
	}
	else {
		return number[k - 1];
	}
}
//????????4 
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 /**
  * Return an array of arrays of size *returnSize.
  * The sizes of the arrays are returned as *returnColumnSizes array.
  * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
  */
int** spiralMatrix(int m, int n, struct ListNode* head, int* returnSize, int** returnColumnSizes) {
	int* number = (int*)malloc(sizeof(int) * (m * n));
	int j = 0;
	struct ListNode* cur = head;
	while (cur) {
		number[j] = cur->val;
		j++;
		cur = cur->next;
	}
	while (j < (m * n)) {
		number[j] = -1;
		j++;
	}
	int row = m;
	int col = n;
	int i = 0;
	int** mat = (int**)malloc(sizeof(int*) * m);
	for (i = 0; i < m; i++) {
		mat[i] = (int*)malloc(sizeof(int) * n);
	}
	i = 0;
	j = 0;
	int f = 0;
	while (f < (m * n)) {
		int i1 = i;
		int j1 = j;
		while (j1 < col) {
			mat[i1][j1] = number[f];
			f++;
			j1++;
		}
		if (f >= (m * n)) {
			break;
		}
		j1--;
		i1++;
		while (i1 < row) {
			mat[i1][j1] = number[f];
			f++;
			i1++;
		}
		if (f >= m * n) {
			break;
		}
		i1--;
		j1--;
		while (j1 >= j) {
			mat[i1][j1] = number[f];
			f++;
			j1--;
		}
		if (f >= m * n) {
			break;
		}
		j1++;
		i1--;
		while (i1 > i) {
			mat[i1][j1] = number[f];
			f++;
			i1--;
		}
		if (f >= m * n) {
			break;
		}
		i++;
		j++;
		row--;
		col--;
	}
	*returnSize = m;
	*returnColumnSizes = (int*)malloc(sizeof(int) * m);
	for (i = 0; i < m; i++) {
		(*returnColumnSizes)[i] = n;
	}
	return mat;
}
//??????????
bool binary_search(int* number, int length, int target) {
	int left = 0;
	int right = length - 1;
	while (left <= right) {
		int mid = (left + right) / 2;
		if (number[mid] == target) {
			return true;
		}
		else if (number[mid] < target) {
			left = mid + 1;
		}
		else {
			right = mid - 1;
		}
	}
	return false;
}
bool searchMatrix(int** matrix, int matrixSize, int matrixColSize, int target) {
	for (int i = 0; i < matrixSize; i++) {
		bool ret = binary_search(matrix[i], matrixColSize, target);
		if (ret == true) {
			return true;
		}
	}
	return false;
}
//?????????????
int compare(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int maxIceCream(int* costs, int costsSize, int coins) {
	//??????
	qsort(costs, costsSize, sizeof(int), compare);
	int count = 0;
	//????coins????????????
	for (int i = 0; i < costsSize; i++) {
		coins -= costs[i];
		if (coins >= 0) {
			count++;
		}
		else {
			break;
		}
	}
	return count;
}
//????????????????

int singleNonDuplicate(int* nums, int numsSize) {
	//???????????
	int* number = (int*)malloc(sizeof(int) * 100000);
	memset(number, 0, sizeof(int) * 100000);
	//???????????????????????????????
	for (int i = 0; i < numsSize; i++) {
		int hashindex = nums[i] - 0;
		number[hashindex] += 1;
	}
	int j = 0;
	//?????????1???????
	for (j = 0; j < 100000; j++) {
		if (number[j] == 1) {
			break;
		}
	}
	return j;
}
//????????????????
int singleNonDuplicate(int* nums, int numsSize) {
	int* number = (int*)malloc(sizeof(int) * 100000);
	memset(number, 0, sizeof(int) * 100000);
	for (int i = 0; i < numsSize; i++) {
		int hashindex = nums[i] - 0;
		number[hashindex] += 1;
	}
	int j = 0;
	for (j = 0; j < 100000; j++) {
		if (number[j] == 1) {
			break;
		}
	}
	return j;
}
//???????????
int diagonalSum(int** mat, int matSize, int* matColSize) {
	int i = 0;
	int col = *matColSize;
	int j = 0;
	int sum = 0;
	for (i = 0; i < matSize; i++) {
		for (j = 0; j < col; j++) {
			if (i == j || i + j == matSize - 1) {
				sum += mat[i][j];
			}
		}
	}
	return sum;
}
//??????????

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
char** printVertically(char* s, int* returnSize) {
	//1.????????????????????????s?????
	char** word = (char**)malloc(sizeof(char*) * 200);
	for (int i = 0; i < 200; i++) {
		word[i] = (char*)malloc(sizeof(char) * 50);
	}
	for (int i = 0; i < 200; i++) {
		memset(word[i], '\0', sizeof(char) * 50);
	}
	int j = 0;
	//????strtok??????????????????????????
	char* string = strtok(s, " ");
	while (string != NULL) {
		strcpy(word[j], string);
		j++;
		string = strtok(NULL, " ");
	}
	//2.?????????????????????????????????
	//???????????????????
	int max = strlen(word[0]);
	for (int i = 1; i < j; i++) {
		if (strlen(word[i]) > max) {
			max = strlen(word[i]);
		}
	}
	//??????????
	char** ver_word = (char**)malloc(sizeof(char*) * max);
	for (int i = 0; i < max; i++) {
		ver_word[i] = (char*)malloc(sizeof(char) * 500);
	}
	for (int i = 0; i < max; i++) {
		memset(ver_word[i], '\0', sizeof(char) * 500);
	}
	int f1 = 0;
	//3.?????word??????????????ver_word
	for (int j1 = 0; j1 < max; j1++) {
		char temp[500] = { 0 };
		int f = 0;
		for (int i1 = 0; i1 < j; i1++) {
			if (word[i1][j1] == '\0') {
				temp[f] = ' ';
				f++;
			}
			else {
				temp[f] = word[i1][j1];
				f++;
			}
		}
		strcpy(ver_word[f1], temp);
		f1++;
	}
	//4.?????0;
	for (int i = 0; i < f1; i++) {
		char* end = ver_word[i] + strlen(ver_word[i]) - 1;
		while (*end == ' ') {
			*end = '\0';
			end--;
		}
	}
	*returnSize = max;
	return ver_word;
}
void reverse(int* arr, int length) {
	int left = 0;
	int right = length - 1;
	while (left <= right) {
		int temp = arr[left];
		arr[left] = arr[right];
		arr[right] = temp;
		left++;
		right--;
	}
}
//?????????
int alternateDigitSum(int n) {
	int* number = (int*)malloc(sizeof(int) * 13);
	int j = 0;
	while (n) {
		number[j] = n % 10;
		j++;
		n /= 10;
	}
	reverse(number, j);
	for (int i = 0; i < j; i++) {
		if (i % 2 != 0) {
			number[i] = -1 * number[i];
		}
	}
	int sum = 0;
	for (int i = 0; i < j; i++) {
		sum += number[i];
	}
	return sum;
}
//???????????????
class Solution {
public:
	string removeStars(string s) {
		int pos;
		//????find?????????????
		while ((pos = s.find('*')) != -1) {
			//????????????????????
			s.erase(pos - 1, 2);
		}
		return s;
	}
};
//???????????????? ||
class Solution {
public:
	int numberOfSpecialChars(string word) {
		vector<char> string1;
		//???????????vector????
		for (int i = 0; i < word.size(); i++) {
			if (word.at(i) >= 'A' && word.at(i) <= 'Z') {
				string1.push_back(word.at(i));
			}
		}
		string1.push_back('\0');
		//??????????
		sort(string1.begin(), string1.end());
		string1.erase(unique(string1.begin(), string1.end()), string1.end());
		int count = 0;
		//????string1????????????????????
		for (vector<char>::iterator it = string1.begin(); it != string1.end(); it++) {
			int pos = word.find(*it);
			int pos1 = word.rfind(*it + 32);
			if (pos1 != -1 && pos1 < pos) {
				count++;
			}
		}
		return count;
	}
};
class Solution {
public:
	vector<int> majorityElement(vector<int>& nums) {
		//?????????????
		set<int> V1;
		//??????????
		multiset<int> V2;
		for (vector<int> ::iterator it = nums.begin(); it != nums.end(); it++) {
			V1.insert(*it);
			V2.insert(*it);
		}
		vector<int> array;
		for (set<int> ::iterator it = V1.begin(); it != V1.end(); it++) {
			if (V2.count(*it) > (V2.size() / 3))
			{
				array.push_back(*it);
			}
		}
		return array;
	}
};
//?k????????
class Mycompare {
public:
	bool operator() (const int& val1, const int& val2)const {
		return val1 > val2;
	}
};
class Solution {
public:
	vector<int> topKFrequent(vector<int>& nums, int k) {
		//????set???????????????????
		set<int> data;
		for (vector<int> ::iterator it = nums.begin(); it != nums.end(); it++) {
			data.insert(*it);
		}
		//????map????,?????????????
		multimap<int, int, Mycompare> Map;
		for (set<int> ::iterator it = data.begin(); it != data.end(); it++) {
			int items = count(nums.begin(), nums.end(), *it);
			Map.insert(make_pair(items, *it));
		}
		vector<int> array;
		int count = 0;
		for (multimap<int, int, Mycompare> ::iterator it = Map.begin(); it != Map.end(); it++) {
			array.push_back((*it).second);
			count++;
			if (count == k) {
				break;
			}
		}
		return array;
	}
};
//??????? K?????????
class Solution {
public:
	int findKthLargest(vector<int>& nums, int k) {
		multiset<int, greater<int>> V;
		for (vector<int> ::iterator it = nums.begin(); it != nums.end(); it++) {
			V.insert(*it);
		}
		int i = 0;
		multiset<int, greater<int>> ::iterator it = V.begin();
		for (; it != V.end() && i < k; it++) {
			i++;
		}
		it--;
		return *it;
	}
};
//????????????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 //??????????:
void insert_sort(int* arr, int length) {
	for (int i = 1; i < length; i++) {
		if (arr[i - 1] > arr[i]) {
			int temp = arr[i];
			int j;
			for (j = i - 1; j >= 0 && temp < arr[j]; j--) {
				arr[j + 1] = arr[j];
			}
			arr[j + 1] = temp;
		}
	}
}
//??????
struct ListNode* insertionSortList(struct ListNode* head) {
	int count = 0;
	struct ListNode* cur = head;
	//???????
	while (cur) {
		count++;
		cur = cur->next;
	}
	//????????
	int* number = (int*)malloc(sizeof(int) * count);
	int j = 0;
	cur = head;
	//??????????????????
	while (cur) {
		number[j] = cur->val;
		j++;
		cur = cur->next;
	}
	//???????????
	insert_sort(number, j);
	//???????????????????
	cur = head;
	j = 0;
	while (cur) {
		cur->val = number[j];
		j++;
		cur = cur->next;
	}
	return head;
}
int compareVersion(char* version1, char* version2) {
	int* version1_number = (int*)malloc(sizeof(int) * 500);//????version1????
	int j1 = 0;
	int* version2_number = (int*)malloc(sizeof(int) * 500);//????version2????
	int j2 = 0;
	char* temp1 = strtok(version1, ".");
	while (temp1 != NULL) {
		version1_number[j1] = atoi(temp1);
		j1++;
		temp1 = strtok(NULL, ".");
	}
	char* temp2 = strtok(version2, ".");
	while (temp2 != NULL) {
		version2_number[j2] = atoi(temp2);
		j2++;
		temp2 = strtok(NULL, ".");
	}
	if (j1 > j2) {
		while (j2 < j1) {
			version2_number[j2] = 0;
			j2++;
		}
	}
	else {
		while (j1 < j2) {
			version1_number[j1] = 0;
			j1++;
		}
	}
	for (int i = 0; i < j1; i++) {
		if (version1_number[i] > version2_number[i]) {
			return 1;
		}
		else if (version1_number[i] < version2_number[i]) {
			return -1;
		}
	}
	return 0;
}
//??????? 
class Solution {
public:
	int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {
		map<int, int> v;//key??????????????????????????????
		for (int i = 0; i < nums1.size(); i++) {
			for (int j = 0; j < nums2.size(); j++) {
				map<int, int> ::iterator it = v.find(nums1.at(i) + nums2.at(j));
				if (it != v.end()) {
					v[(*it).first] += 1;
				}
				else {
					v.insert(make_pair(nums1.at(i) + nums2.at(j), 1));
				}
			}
		}
		int count = 0;
		for (int i = 0; i < nums3.size(); i++) {
			for (int j = 0; j < nums4.size(); j++) {
				map<int, int> ::iterator it = v.find(-(nums3.at(i) + nums4.at(j)));
				if (it != v.end()) {
					count += v[(*it).first];
				}
			}
		}
		return count;
	}
};
//???????
class Solution {
public:
	vector<vector<int>> threeSum(vector<int>& nums) {
		int len = nums.size();
		vector<vector<int>> ans;
		sort(nums.begin(), nums.end());
		for (int i = 0; i < len; i++) {
			int left = i + 1, right = len - 1;
			if (i != 0 && nums[i] == nums[i - 1]) continue; // ????nums[i]??????????????
			while (left < right) {
				if (nums[i] + nums[left] + nums[right] == 0) {
					ans.push_back({ nums[i], nums[left], nums[right] });
					left++;
					right--;
					while (left < right && nums[left] == nums[left - 1]) left++; // ???????????????
					while (left < right && nums[right] == nums[right + 1]) right--; // ???????????????
				}
				else if (nums[i] + nums[left] + nums[right] > 0) right--;
				else left++;
			}
		}
		return ans;
	}
};
//??????????
class Solution {
public:
	string removeDuplicates(string s) {
		string v;
		int flag = 1;
		for (int i = 0; i < s.size(); i++) {
			if (v.size() == 0) {
				v.push_back(s.at(i));
			}
			else {
				if (s.at(i) != v.at(v.size() - 1)) {
					v.push_back(s.at(i));
				}
				else {
					v.pop_back();
				}
			}
		}
		return v;
	}
};
//????????
class Solution {
public:
	int evalRPN(vector<string>& tokens) {
		stack<int> v;
		for (int i = 0; i < tokens.size(); i++) {
			if (tokens.at(i) != "+" && tokens.at(i) != "-" && tokens.at(i) != "*" && tokens.at(i) != "/") {
				int temp = stoi(tokens.at(i));
				v.push(temp);
			}
			else {
				int number1 = v.top();
				v.pop();
				int number2 = v.top();
				v.pop();
				if (tokens.at(i) == "+") {
					int temp = number2 + number1;
					v.push(temp);
				}
				else if (tokens.at(i) == "-") {
					int temp = number2 - number1;
					v.push(temp);
				}
				else if (tokens.at(i) == "/") {
					int temp = number2 / number1;
					v.push(temp);
				}
				else if (tokens.at(i) == "*") {
					int temp = number2 * number1;
					v.push(temp);
				}
			}
		}
		return v.top();
	}
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
 //???????
class Solution {
public:
	vector<vector<int>> levelOrder(TreeNode* root) {
		queue<TreeNode*> sequence;
		vector<vector<int>> result;
		if (root == NULL) {
			return result;
		}
		sequence.push(root);
		int size = 1;
		int count = 1;
		int nextcount = 0;
		while (size != 0) {
			vector<int> array;
			for (int i = 0; i < count; i++) {
				TreeNode* temp = sequence.front();
				array.push_back(temp->val);
				if (temp->left != NULL) {
					sequence.push(temp->left);
					nextcount++;
					size++;
				}
				if (temp->right != NULL) {
					sequence.push(temp->right);
					nextcount++;
					size++;
				}
				sequence.pop();
				size--;
			}
			count = nextcount;
			nextcount = 0;
			result.push_back(array);
			array.clear();
		}
		return result;
	}
};
//?k????????
class Mycompare {
public:
	bool operator() (const int& val1, const int& val2)const {
		return val1 > val2;
	}
};
class Solution {
public:
	vector<int> topKFrequent(vector<int>& nums, int k) {
		//????set???????????????????
		set<int> data;
		for (vector<int> ::iterator it = nums.begin(); it != nums.end(); it++) {
			data.insert(*it);
		}
		//????map????,?????????????
		multimap<int, int, Mycompare> Map;
		for (set<int> ::iterator it = data.begin(); it != data.end(); it++) {
			int items = count(nums.begin(), nums.end(), *it);
			Map.insert(make_pair(items, *it));
		}
		vector<int> array;
		int count = 0;
		for (multimap<int, int, Mycompare> ::iterator it = Map.begin(); it != Map.end(); it++) {
			array.push_back((*it).second);
			count++;
			if (count == k) {
				break;
			}
		}
		return array;
	}
};
//??????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	int maxDepth(TreeNode* root) {
		if (root == NULL)
		{
			return 0;
		}
		int leftheight = maxDepth(root->left);
		int rightheight = maxDepth(root->right);
		int height = 1 + max(leftheight, rightheight);
		return height;
	}
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
 //??????????
class Solution {
public:
	void find_bottom(TreeNode* root, int& maxdepth, int& depth, int& result) {
		if (root->left == NULL && root->right == NULL) {
			if (depth > maxdepth) {
				maxdepth = depth;
				result = root->val;
			}
		}
		if (root->left != NULL) {
			depth++;
			find_bottom(root->left, maxdepth, depth, result);
			depth--;
		}
		if (root->right != NULL) {
			depth++;
			find_bottom(root->right, maxdepth, depth, result);
			depth--;
		}
	}
	int findBottomLeftValue(TreeNode* root) {
		int max = 0;
		int depth = 1;
		int result = 0;
		find_bottom(root, max, depth, result);
		return result;
	}
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
 //????????????????
class Solution {
public:
	TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
		if (postorder.size() == 0)return NULL;
		int rootval = postorder.at(postorder.size() - 1);
		TreeNode* root = new TreeNode(rootval);
		if (postorder.size() == 1) {
			return root;
		}
		int index = 0;
		for (index = 0; index < inorder.size(); index++) {
			if (inorder[index] == rootval) {
				break;
			}
		}
		//??????
		vector<int> left_in_array;
		left_in_array.insert(left_in_array.begin(), inorder.begin(), inorder.begin() + index);

		//??????
		vector<int> right_in_array;
		right_in_array.insert(right_in_array.begin(), inorder.begin() + index + 1, inorder.end());
		//????????? 
		postorder.resize(postorder.size() - 1);
		//?????
		vector<int> left_post_array;
		left_post_array.insert(left_post_array.begin(), postorder.begin(), postorder.begin() + left_in_array.size());
		//?????
		vector<int> right_post_array;
		right_post_array.insert(right_post_array.begin(), postorder.begin() + left_in_array.size(), postorder.end());
		root->left = buildTree(left_in_array, left_post_array);
		root->right = buildTree(right_in_array, right_post_array);
		return root;
	}
};
//?????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	TreeNode* pre = NULL;
	bool isValidBST(TreeNode* root) {
		if (root == NULL) {
			return true;
		}
		bool left = isValidBST(root->left);
		if (pre != NULL && pre->val >= root->val) {
			return false;
		}
		pre = root;
		bool right = isValidBST(root->right);
		return left && right;
	}
};
//?????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	void sum_tree(TreeNode* root, vector<int>& array, vector<vector<int>>& result) {
		if (root->left == NULL && root->right == NULL) {
			result.push_back(array);
			return;
		}
		if (root->left != NULL) {
			array.push_back(root->left->val);
			sum_tree(root->left, array, result);
			array.pop_back();
		}
		if (root->right != NULL) {
			array.push_back(root->right->val);
			sum_tree(root->right, array, result);
			array.pop_back();
		}
	}
	int sumNumbers(TreeNode* root) {
		vector<int> array;
		vector<vector<int>> result;
		array.push_back(root->val);
		sum_tree(root, array, result);
		int sum = 0;
		for (int i = 0; i < result.size(); i++) {
			int length = result[i].size();
			int rowsum = 0;
			for (int j = 0; j < length; j++) {
				rowsum += (result[i][j] * pow(10, length - j - 1));
			}
			sum += rowsum;
		}
		return sum;
	}
};
//??????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	TreeNode* insertIntoBST(TreeNode* root, int val) {
		if (root == NULL) {
			TreeNode* node = new TreeNode(val);
			return node;
		}
		if (root->val > val) {
			root->left = insertIntoBST(root->left, val);
		}
		if (root->val < val) {
			root->right = insertIntoBST(root->right, val);
		}
		return root;
	}
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
 //?????????????????
class Solution {
public:
	TreeNode* deleteNode(TreeNode* root, int key) {
		//????????????????????????????NULL
		if (root == NULL || (root->left == NULL && root->right == NULL && root->val == key)) {
			return NULL;
		}
		//??????????????????????????????????
		if (root->left != NULL && root->right == NULL && root->val == key) {
			return root->left;
		}
		//???????????????????????????????????
		if (root->left == NULL && root->right != NULL && root->val == key) {
			return root->right;
		}
		//???????????????????????????????? ?????????????????????
		if (root->left != NULL && root->right != NULL && root->val == key) {
			TreeNode* right_node = root->right;
			TreeNode* cur = right_node;
			while (cur->left != NULL) {
				cur = cur->left;
			}
			cur->left = root->left;
			return root->right;
		}
		if (root->val > key) {
			root->left = deleteNode(root->left, key);
		}
		if (root->val < key) {
			root->right = deleteNode(root->right, key);
		}
		return root;
	}
};
//??????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	void find_value(TreeNode* root, int& value, int& height, int& maxheight) {
		if (root->left == NULL && root->right == NULL) {
			if (height > maxheight) {
				value = root->val;
				maxheight = height;
			}
			return;
		}
		if (root->left != NULL) {
			height++;
			find_value(root->left, value, height, maxheight);
			height--;
		}
		if (root->right != NULL) {
			height++;
			find_value(root->right, value, height, maxheight);
			height--;
		}
	}
	int findBottomLeftValue(TreeNode* root) {
		int maxheight = 1;
		int height = 1;
		int value = root->val;
		find_value(root, value, height, maxheight);
		return value;
	}
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	TreeNode* trimBST(TreeNode* root, int low, int high) {
		if (root == NULL) {
			return NULL;
		}
		if (root->val < low) {
			return trimBST(root->right, low, high);
		}
		if (root->val > high) {
			return trimBST(root->left, low, high);
		}
		root->left = trimBST(root->left, low, high);
		root->right = trimBST(root->right, low, high);
		return root;
	}
};
//??????
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(int& sum, int startindex, vector<int>& candidates, int target) {
		if (sum > target) {
			return;
		}
		if (sum == target) {
			result.push_back(array);
			return;
		}
		for (int i = startindex; i < candidates.size(); i++) {
			sum += candidates.at(i);
			array.push_back(candidates.at(i));
			backtricking(sum, i, candidates, target);
			sum -= candidates.at(i);
			array.pop_back();
		}
	}
	vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
		int startindex = 0;
		int sum = 0;
		backtricking(sum, startindex, candidates, target);
		return result;
	}
};
//??????????
class Solution {
public:
	vector<string> result;
	string array;
	string lettermap[10] = { "","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };
	void backtricking(string digits, int startindex) {
		if (array.size() == digits.size()) {
			result.push_back(array);
			return;
		}
		for (int i = startindex; i < digits.size(); i++) {
			int index = digits[i] - '0';
			for (int j = 0; j < lettermap[index].size(); j++) {
				array.push_back(lettermap[index][j]);
				backtricking(digits, i + 1);
				array.pop_back();
			}
		}
	}
	vector<string> letterCombinations(string digits) {
		if (digits.size() == 0) {
			return result;
		}
		int startindex = 0;
		backtricking(digits, startindex);
		return result;
	}
};
//??????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	TreeNode* insertIntoBST(TreeNode* root, int val) {
		if (root == NULL) {
			TreeNode* node = new TreeNode(val);
			return node;
		}
		if (root->val > val) {
			root->left = insertIntoBST(root->left, val);
		}
		if (root->val < val) {
			root->right = insertIntoBST(root->right, val);
		}
		return root;
	}
};
//???????
class Solution {
public:
	vector<vector<int>> fourSum(vector<int>& nums, int target) {
		vector<vector<int>> result;
		sort(nums.begin(), nums.end());
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] > target && nums[i] >= 0 && target >= 0)
				break;
			if (i > 0 && nums[i] == nums[i - 1]) {
				continue;
			}
			for (int k = i + 1; k < nums.size(); k++) {
				if (nums[i] + nums[k] > target && nums[k] + nums[i] >= 0 && target >= 0) {
					break;
				}
				if (k > i + 1 && nums[k] == nums[k - 1]) {
					continue;
				}
				int left = k + 1;
				int right = nums.size() - 1;
				while (left < right) {
					if ((long)nums[i] + nums[k] + nums[left] + nums[right] > target) {
						right--;
					}
					else if ((long)nums[i] + nums[k] + nums[left] + nums[right] < target) {
						left++;
					}
					else {
						result.push_back(vector<int>{nums[i], nums[k], nums[left], nums[right]});
						while (left < right && nums[left] == nums[left + 1]) {
							left++;
						}
						while (left < right && nums[right] == nums[right - 1]) {
							right--;
						}
						left++;
						right--;
					}
				}
			}
		}
		return result;
	}
};
//???????
class Solution {
public:
	bool judge_palindromes(string s, int startindex, int i) {
		while (startindex <= i) {
			if (s.at(startindex) != s.at(i)) {
				return false;
			}
			startindex++;
			i--;
		}
		return true;
	}
	vector<vector<string>> result;
	vector<string> array;
	void backtricking(string s, int startindex) {
		if (startindex >= s.size()) {
			result.push_back(array);
			return;
		}
		for (int i = startindex; i < s.size(); i++) {
			if (judge_palindromes(s, startindex, i) == true) {
				string temp(s.begin() + startindex, s.begin() + i + 1);
				array.push_back(temp);
			}
			else {
				continue;
			}
			backtricking(s, i + 1);
			array.pop_back();
		}
	}
	vector<vector<string>> partition(string s) {
		int startindex = 0;
		backtricking(s, startindex);
		return result;
	}
};
//???ip???
class Solution {
public:
	vector<string> result;// ??????
	// startIndex: ?????????????pointNum:???????????
	void backtracking(string& s, int startIndex, int pointNum) {
		if (pointNum == 3) { // ?????????3?????????
			// ???????????????????????????????result??
			if (isValid(s, startIndex, s.size() - 1)) {
				result.push_back(s);
			}
			return;
		}
		for (int i = startIndex; i < s.size(); i++) {
			if (isValid(s, startIndex, i)) { // ??? [startIndex,i] ????????????????
				s.insert(s.begin() + i + 1, '.');  // ??i???????????????
				pointNum++;
				backtracking(s, i + 2, pointNum);   // ??????????????????????????i+2
				pointNum--;                         // ????
				s.erase(s.begin() + i + 1);         // ??????????
			}
			else break; // ????????????????????
		}
	}
	// ????????s????????????[start, end]???????????????
	bool isValid(const string& s, int start, int end) {
		if (start > end) {
			return false;
		}
		if (s[start] == '0' && start != end) { // 0?????????????
			return false;
		}
		int num = 0;
		for (int i = start; i <= end; i++) {
			if (s[i] > '9' || s[i] < '0') { // ??????????????????
				return false;
			}
			num = num * 10 + (s[i] - '0');
			if (num > 255) { // ???????255??????
				return false;
			}
		}
		return true;
	}
	vector<string> restoreIpAddresses(string s) {
		result.clear();
		if (s.size() < 4 || s.size() > 12) return result; // ????????
		backtracking(s, 0, 0);
		return result;
	}
};
//?????
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(vector<int>& nums, int startindex, vector<bool>& used) {
		if (array.size() <= nums.size()) {
			result.push_back(array);
		}
		for (int i = startindex; i < nums.size(); i++) {
			if (i > startindex && nums[i] == nums[i - 1] && used[i - 1] == false) {
				continue;
			}
			used[i] = true;
			array.push_back(nums[i]);
			backtricking(nums, i + 1, used);
			used[i] = false;
			array.pop_back();
		}
	}
	vector<vector<int>> subsetsWithDup(vector<int>& nums) {
		sort(nums.begin(), nums.end());
		int startindex = 0;
		vector<bool> used;
		used.resize(nums.size(), false);
		backtricking(nums, startindex, used);
		return result;
	}
};
//?????
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(vector<int>& nums, vector<bool>& used) {
		if (array.size() == nums.size()) {
			result.push_back(array);
		}
		for (int i = 0; i < nums.size(); i++) {
			if (used[i] != true) {
				array.push_back(nums[i]);
				used[i] = true;
				backtricking(nums, used);
				array.pop_back();
				used[i] = false;
			}
			else {
				continue;
			}
		}
	}
	vector<vector<int>> permute(vector<int>& nums) {
		vector<bool> used;
		used.resize(nums.size(), false);
		backtricking(nums, used);
		return result;
	}
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
 //????????????????????????
class Solution {
public:
	ListNode* modifiedList(vector<int>& nums, ListNode* head) {
		//?????????set??????
		multiset<int> array(nums.begin(), nums.end());
		ListNode* cur = head;
		//????????????
		while (cur->next != NULL) {
			//?????????????????????????????????????
			if (cur == head && array.find(cur->val) != array.end()) {
				head = cur->next;
				delete cur;
				cur = head;
			}
			else if (array.find(cur->next->val) != array.end()) {//??????????????????????????????????????????????????
				ListNode* p = cur->next;
				cur->next = p->next;
				p->next = NULL;
				delete p;
			}
			else {
				cur = cur->next;
			}
		}
		return head;
	}
};
//??????????
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(vector<int>& nums, int startindex) {
		if (array.size() <= nums.size() && array.size() >= 2) {
			result.push_back(array);
		}
		unordered_set<int> uset;
		for (int i = startindex; i < nums.size(); i++) {
			if ((array.size() != 0 && nums[i] < array.at(array.size() - 1)) || uset.find(nums[i]) != uset.end()) {
				continue;
			}
			uset.insert(nums[i]);
			array.push_back(nums.at(i));
			backtricking(nums, i + 1);
			array.pop_back();
		}
	}
	vector<vector<int>> findSubsequences(vector<int>& nums) {
		int startindex = 0;
		backtricking(nums, startindex);
		return result;
	}
};
//?????||
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(vector<int>& nums, vector<bool>& used) {
		if (array.size() == nums.size()) {
			result.push_back(array);
			return;
		}
		for (int i = 0; i < nums.size(); i++) {
			if (i > 0 && nums[i] == nums[i - 1] && used[i - 1] == false) {
				continue;
			}
			if (used[i] == false) {
				array.push_back(nums[i]);
				used[i] = true;
				backtricking(nums, used);
				array.pop_back();
				used[i] = false;
			}
			else {
				continue;
			}
		}
	}
	vector<vector<int>> permuteUnique(vector<int>& nums) {
		sort(nums.begin(), nums.end());
		vector<bool> used;
		used.resize(nums.size(), false);
		backtricking(nums, used);
		return result;
	}
};
//????????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	multimap<int, int> array;
	int findmaxsum(TreeNode* root) {
		if (root == NULL) {
			return 0;
		}
		int leftvalue = findmaxsum(root->left);
		int rightvalue = findmaxsum(root->right);
		int result = root->val + leftvalue + rightvalue;
		multimap<int, int> ::iterator it = array.find(result);
		if (it != array.end()) {
			(it->second)++;
		}
		else {
			array.insert(make_pair(result, 1));
		}
		return result;
	}
	vector<int> findFrequentTreeSum(TreeNode* root) {
		vector<int> result;
		int sum = findmaxsum(root);
		int max = 0;
		for (multimap<int, int> ::iterator it = array.begin(); it != array.end(); it++) {
			if (it->second > max) {
				max = it->second;
			}
		}
		for (multimap<int, int> ::iterator it = array.begin(); it != array.end(); it++) {
			if (it->second == max) {
				result.push_back(it->first);
			}
		}
		return result;
	}
};
//?????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
 /**
  * Definition for singly-linked list.
  * struct ListNode {
  *     int val;
  *     ListNode *next;
  *     ListNode(int x) : val(x), next(NULL) {}
  * };
  */
class Solution {
public:
	vector<ListNode*> listOfDepth(TreeNode* tree) {
		vector<ListNode*>  result;
		int count = 1;
		int nextcount = 0;
		queue<TreeNode*> queuece;
		queuece.push(tree);
		int size = 1;
		while (size != 0) {
			ListNode* p = NULL;
			ListNode* tail = NULL;
			for (int i = 0; i < count; i++) {
				TreeNode* temp = queuece.front();
				if (p == NULL) {
					p = new ListNode(temp->val);
					tail = p;
				}
				else {
					ListNode* newnode = new ListNode(temp->val);
					tail->next = newnode;
					tail = newnode;
				}
				if (temp->left != NULL) {
					queuece.push(temp->left);
					nextcount++;
					size++;
				}
				if (temp->right != NULL) {
					queuece.push(temp->right);
					nextcount++;
					size++;
				}
				queuece.pop();
				size--;
			}
			count = nextcount;
			result.push_back(p);
			nextcount = 0;
		}
		return result;
	}
};
//??????????
class Solution {
public:
	void rangeadd(vector<vector<int>>& result, vector<int>& index) {
		int i, j;
		for (i = index[0]; i <= index[2]; i++) {
			for (j = index[1]; j <= index[3]; j++) {
				result[i][j] += 1;
			}
		}
	}
	vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {
		vector<vector<int>> result;
		result.resize(n);
		for (int i = 0; i < n; i++) {
			result[i].resize(n, 0);
		}
		for (int i = 0; i < queries.size(); i++) {
			rangeadd(result, queries[i]);
		}
		return result;
	}
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
 //??????????????????????
class Solution {
public:
	ListNode* modifiedList(vector<int>& nums, ListNode* head) {
		//?????????set??????
		multiset<int> array(nums.begin(), nums.end());
		ListNode* cur = head;
		//????????????
		while (cur->next != NULL) {
			//?????????????????????????????????????
			if (cur == head && array.find(cur->val) != array.end()) {
				head = cur->next;
				delete cur;
				cur = head;
			}
			else if (array.find(cur->next->val) != array.end()) {//??????????????????????????????????????????????????
				ListNode* p = cur->next;
				cur->next = p->next;
				p->next = NULL;
				delete p;
			}
			else {
				cur = cur->next;
			}
		}
		return head;
	}
};
//???
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(int startindex, vector<int>& nums) {
		if (array.size() <= nums.size()) {
			result.push_back(array);
		}
		for (int i = startindex; i < nums.size(); i++) {
			array.push_back(nums[i]);
			backtricking(i + 1, nums);
			array.pop_back();
		}
	}
	vector<vector<int>> subsets(vector<int>& nums) {
		int startindex = 0;
		backtricking(startindex, nums);
		return result;
	}
};
//????????
class Solution {
public:
	vector<string> result;
	string str;
	bool isValid(string s) {
		stack<char> v;
		for (int i = 0; i < s.size(); i++) {
			if (s.at(i) == '(') {
				v.push(')');
			}
			else {
				if (v.size() == 0) {
					return false;
				}
				if (s.at(i) == v.top()) {
					v.pop();
				}
				else {
					return false;
				}
			}
		}
		if (v.size() != 0) {
			return false;
		}
		else {
			return true;
		}
	}
	void backtricking(string path, vector<bool>& used) {
		if (str.size() == path.size()) {
			if (isValid(str) == true) {
				result.push_back(str);
			}
		}
		for (int i = 0; i < path.size(); i++) {
			if (i > 0 && path[i] == path[i - 1] && used[i - 1] == false) {
				continue;
			}
			if (used[i] == false) {
				str += path[i];
				used[i] = true;
				backtricking(path, used);
				str.pop_back();
				used[i] = false;
			}
			else {
				continue;
			}
		}
	}
	vector<string> generateParenthesis(int n) {
		string path;
		int i = 0;
		while (i < n) {
			path += '(';
			i++;
		}
		i = 0;
		while (i < n) {
			path += ')';
			i++;
		}
		vector<bool> used;
		used.resize(path.size(), false);
		backtricking(path, used);
		return result;
	}
};
//??????
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(int startindex, int n, int k) {
		if (array.size() == k) {
			result.push_back(array);
			return;
		}
		for (int i = startindex; i <= n; i++) {
			array.push_back(i);
			backtricking(i + 1, n, k);
			array.pop_back();
		}
	}
	vector<vector<int>> combine(int n, int k) {
		int startindex = 1;
		backtricking(startindex, n, k);
		return result;
	}
};
//???????
class Solution {
public:
	int findContentChildren(vector<int>& g, vector<int>& s) {
		if (s.size() == 0) {
			return 0;
		}
		sort(g.begin(), g.end());
		sort(s.begin(), s.end());
		int count = 0;
		while (g.size() != 0 && s.size() != 0) {
			if (s.at(s.size() - 1) < g.at(g.size() - 1)) {
				g.pop_back();
			}
			else {
				count++;
				g.pop_back();
				s.pop_back();
			}
		}
		return count;

	}
};
//???????????????????
class Solution {
public:
	vector<string> result;
	string str;
	void backtricking(string S, vector<bool>& used) {
		if (str.size() == S.size()) {
			result.push_back(str);
		}
		for (int i = 0; i < S.size(); i++) {
			if (used[i] == false) {
				str.push_back(S[i]);
				used[i] = true;
				backtricking(S, used);
				str.pop_back();
				used[i] = false;
			}
			else {
				continue;
			}
		}
	}
	vector<string> permutation(string S) {
		vector<bool> used;
		used.resize(S.size(), false);
		backtricking(S, used);
		return result;
	}
};
//???????
class Solution {
public:
	string convertToBase7(int num) {
		string s;
		int n = abs(num);
		if (num == 0) {
			s.push_back('0');
			return s;
		}
		while (n) {
			s.push_back(n % 7 + '0');
			n /= 7;
		}
		if (num < 0) {
			s.push_back('-');
		}
		reverse(s.begin(), s.end());
		return s;
	}
};
//?????
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(vector<int>& nums, vector<bool>& used) {
		if (array.size() == nums.size()) {
			result.push_back(array);
		}
		for (int i = 0; i < nums.size(); i++) {
			if (used[i] == false) {
				array.push_back(nums[i]);
				used[i] = true;
				backtricking(nums, used);
				array.pop_back();
				used[i] = false;
			}
			else {
				continue;
			}
		}
	}
	vector<vector<int>> permute(vector<int>& nums) {
		vector<bool> used;
		used.resize(nums.size(), false);
		backtricking(nums, used);
		return result;
	}
};
//???
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(int startindex, vector<int>& nums) {
		if (array.size() <= nums.size()) {
			result.push_back(array);
		}
		for (int i = startindex; i < nums.size(); i++) {
			array.push_back(nums[i]);
			backtricking(i + 1, nums);
			array.pop_back();
		}
	}
	vector<vector<int>> subsets(vector<int>& nums) {
		int startindex = 0;
		backtricking(startindex, nums);
		return result;
	}
};
//?????????????????
class Solution {
public:
	vector<string> result;
	string s;
	void backtricking(string S, vector<bool>& used) {
		if (s.size() == S.size()) {
			result.push_back(s);
			return;
		}
		for (int i = 0; i < S.size(); i++) {
			if (i > 0 && S[i] == S[i - 1] && used[i - 1] == false) {
				continue;
			}
			if (used[i] == false) {
				used[i] = true;
				s.push_back(S[i]);
				backtricking(S, used);
				used[i] = false;
				s.pop_back();
			}
		}
	}
	vector<string> permutation(string S) {
		sort(S.begin(), S.end());
		vector<bool> used;
		used.resize(S.size(), false);
		backtricking(S, used);
		return result;
	}
};
//??????
class Solution {
public:
	vector<vector<int>> transpose(vector<vector<int>>& matrix) {
		vector<vector<int>> result;
		result.resize(matrix[0].size());
		for (int i = 0; i < matrix[0].size(); i++) {
			result[i].resize(matrix.size());
		}
		int f = 0;
		for (int j = 0; j < matrix[0].size(); j++) {
			int index = 0;
			for (int i = 0; i < matrix.size(); i++) {
				result[f][index] = matrix[i][j];
				index++;
			}
			f++;
		}
		return result;
	}
};
//???????
class SubrectangleQueries {
public:
	vector<vector<int>> result;
	SubrectangleQueries(vector<vector<int>>& rectangle) {
		result = rectangle;
	}

	void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
		for (int i = row1; i <= row2; i++) {
			for (int j = col1; j <= col2; j++) {
				result[i][j] = newValue;
			}
		}
	}

	int getValue(int row, int col) {
		return result[row][col];
	}
};

/**
 * Your SubrectangleQueries object will be instantiated and called as such:
 * SubrectangleQueries* obj = new SubrectangleQueries(rectangle);
 * obj->updateSubrectangle(row1,col1,row2,col2,newValue);
 * int param_2 = obj->getValue(row,col);
 */
 /**
  * Definition for a binary tree node.
  * struct TreeNode {
  *     int val;
  *     TreeNode *left;
  *     TreeNode *right;
  *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
  *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  * };
  */
  //??????????????????????
class FindElements {
public:
	vector<int> array;
	FindElements(TreeNode* root) {
		int count = 1;
		int nextcount = 0;
		queue<TreeNode*> dequence;
		root->val = 0;
		dequence.push(root);
		int size = 1;
		//??????????????????????????
		while (size != 0) {
			for (int i = 0; i < count; i++) {
				TreeNode* temp = dequence.front();
				array.push_back(temp->val);
				if (temp->left != NULL) {
					temp->left->val = 2 * (temp->val) + 1;
					dequence.push(temp->left);
					nextcount++;
					size++;
				}
				if (temp->right != NULL) {
					temp->right->val = 2 * (temp->val) + 2;
					dequence.push(temp->right);
					nextcount++;
					size++;
				}
				dequence.pop();
				size--;
			}
			count = nextcount;
			nextcount = 0;
		}
	}

	bool find(int target) {
		for (int i = 0; i < array.size(); i++) {
			if (array[i] == target) {
				return true;
			}
		}
		return false;
	}
};

/**
 * Your FindElements object will be instantiated and called as such:
 * FindElements* obj = new FindElements(root);
 * bool param_1 = obj->find(target);
 */
 //303.????????-?????? 
class NumArray {
public:
	vector<int> array;
	NumArray(vector<int>& nums) {
		array = nums;
	}

	int sumRange(int left, int right) {
		int sum = 0;
		while (left <= right) {
			sum += array[left];
			left++;
		}
		return sum;
	}
};

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray* obj = new NumArray(nums);
 * int param_1 = obj->sumRange(left,right);
 */
 //????????
class Solution {
public:
	int equalPairs(vector<vector<int>>& grid) {
		//??????????????????grid???????????
		vector<vector<int>> result;
		result.resize(grid[0].size());
		for (int i = 0; i < grid[0].size(); i++) {
			result[i].resize(grid.size(), 0);
		}
		int f = 0;
		for (int j = 0; j < grid[0].size(); j++) {
			int index = 0;
			for (int i = 0; i < grid.size(); i++) {
				result[f][index] = grid[i][j];
				index++;
			}
			f++;
		}
		int count = 0;
		//???????????????????????
		for (int i = 0; i < result.size(); i++) {
			for (int j = 0; j < grid.size(); j++) {
				if (result[i] == grid[j]) {
					count++;
				}
			}
		}
		return count;
	}
};
//????????????????
class Solution {
public:
	string removeTrailingZeros(string num) {
		while (num[num.size() - 1] == '0') {
			num.pop_back();
		}
		return num;
	}
};
//????????????
class Solution {
public:
	vector<int> shuffle(vector<int>& nums, int n) {
		vector<int> x_array(nums.begin(), nums.begin() + n);
		vector<int> y_array(nums.begin() + n, nums.end());
		int x_index = 0;
		int y_index = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (i % 2 == 0) {
				nums[i] = x_array[x_index];
				x_index++;
			}
			else {
				nums[i] = y_array[y_index];
				y_index++;
			}
		}
		return nums;
	}
};
//?????????????
class Solution {
public:
	bool hasAlternatingBits(int n) {
		int num = n;
		vector<int> array;
		while (num) {
			array.push_back(num % 2);
			num = num / 2;
		}
		reverse(array.begin(), array.end());
		for (int i = 1; i < array.size(); i++) {
			if (array[i] == array[i - 1]) {
				return false;
			}
		}
		return true;
	}
};
//???????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
	vector<int> array;
	Solution(ListNode* head) {
		ListNode* cur = head;
		while (cur) {
			array.push_back(cur->val);
			cur = cur->next;
		}
		srand((unsigned)time(NULL));
	}

	int getRandom() {
		int randomindex = rand() % array.size();
		return array[randomindex];
	}
};

/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(head);
 * int param_1 = obj->getRandom();
 */
 /**
  * Definition for a binary tree node.
  * struct TreeNode {
  *     int val;
  *     TreeNode *left;
  *     TreeNode *right;
  *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
  *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
  *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  * };
  */
class BSTIterator {
public:
	vector<int> tree_val;
	int i;
	void inorder_travel(TreeNode* root) {
		if (root == NULL) {
			return;
		}
		inorder_travel(root->left);
		tree_val.push_back(root->val);
		inorder_travel(root->right);
	}
	BSTIterator(TreeNode* root) {
		inorder_travel(root);
		i = -1;
	}

	int next() {
		this->i++;
		return tree_val[i];
	}

	bool hasNext() {
		if (i + 1 >= tree_val.size()) {
			return false;
		}
		else {
			return true;
		}
	}
};
//??????????
/**
 * Your BSTIterator object will be instantiated and called as such:
 * BSTIterator* obj = new BSTIterator(root);
 * int param_1 = obj->next();
 * bool param_2 = obj->hasNext();
 */
class MyCircularQueue {
public:
	int front;
	int rear;
	vector<int> queue;
	//?????
	MyCircularQueue(int k) {
		queue.resize(k + 1);
		front = rear = 0;
	}
	//???
	bool enQueue(int value) {
		if (isFull() == true) {
			return false;
		}
		else {
			queue[rear] = value;
			rear = (rear + 1) % queue.size();
			return true;
		}
	}
	//????
	bool deQueue() {
		if (isEmpty() == true) {
			return false;
		}
		else {
			front = (front + 1) % queue.size();
			return true;
		}
	}
	//??????????
	int Front() {
		if (isEmpty() == true) {
			return -1;
		}
		else {
			return queue[front];
		}
	}
	//??????
	int Rear() {
		if (isEmpty() == true) {
			return -1;
		}
		else {
			if (rear == 0) {
				return queue[queue.size() - 1];
			}
			return queue[rear - 1];
		}

	}
	//?????????
	bool isEmpty() {
		if (front == rear) {
			return true;
		}
		else {
			return false;
		}
	}
	//??????????
	bool isFull() {
		if ((rear + 1) % queue.size() == (front) % queue.size()) {
			return true;
		}
		else {
			return false;
		}
	}
};

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue* obj = new MyCircularQueue(k);
 * bool param_1 = obj->enQueue(value);
 * bool param_2 = obj->deQueue();
 * int param_3 = obj->Front();
 * int param_4 = obj->Rear();
 * bool param_5 = obj->isEmpty();
 * bool param_6 = obj->isFull();
 */
class Bank {
public:
	vector<long long> bank_account;
	Bank(vector<long long>& balance) {
		bank_account = balance;
	}

	bool transfer(int account1, int account2, long long money) {
		if (account1 > bank_account.size() || account2 > bank_account.size()) {
			return false;
		}
		if (bank_account[account1 - 1] >= money) {
			bank_account[account1 - 1] -= money;
			bank_account[account2 - 1] += money;
			return true;
		}
		else {
			return false;
		}
	}

	bool deposit(int account, long long money) {
		if (account > bank_account.size()) {
			return false;
		}
		else {
			bank_account[account - 1] += money;
			return true;
		}
	}

	bool withdraw(int account, long long money) {
		if (account > bank_account.size()) {
			return false;
		}
		if (bank_account[account - 1] >= money) {
			bank_account[account - 1] -= money;
			return true;
		}
		else {
			return false;
		}
	}
};

/**
 * Your Bank object will be instantiated and called as such:
 * Bank* obj = new Bank(balance);
 * bool param_1 = obj->transfer(account1,account2,money);
 * bool param_2 = obj->deposit(account,money);
 * bool param_3 = obj->withdraw(account,money);
 */
 //????????????????????
class CustomStack {
public:
	vector<int> array;
	int Maxsize;
	CustomStack(int maxSize) {
		Maxsize = maxSize;
		array.clear();
	}

	void push(int x) {
		if (array.size() == Maxsize) {
			return;
		}
		else {
			array.push_back(x);
		}
	}

	int pop() {
		if (array.size() == 0) {
			return -1;
		}
		else {
			int pop_figure = array[array.size() - 1];
			array.pop_back();
			return pop_figure;
		}
	}

	void increment(int k, int val) {
		if (k >= array.size()) {
			for (int i = 0; i < array.size(); i++) {
				array[i] += val;
			}
		}
		else {
			for (int i = 0; i < k; i++) {
				array[i] += val;
			}
		}
	}
};

/**
 * Your CustomStack object will be instantiated and called as such:
 * CustomStack* obj = new CustomStack(maxSize);
 * obj->push(x);
 * int param_2 = obj->pop();
 * obj->increment(k,val);
 */
 //??????
class Solution {
public:
	void replace_photo(vector<int>& array) {
		for (int i = 0; i < array.size(); i++) {
			if (array[i] == 1) {
				array[i] = 0;
			}
			else {
				array[i] = 1;
			}
		}
	}
	vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image) {
		for (int i = 0; i < image.size(); i++) {
			reverse(image[i].begin(), image[i].end());
		}
		for (int i = 0; i < image.size(); i++) {
			replace_photo(image[i]);
		}
		return image;
	}
};
//????????????????
class Solution {
public:
	vector<int> targetIndices(vector<int>& nums, int target) {
		vector<int> result;
		sort(nums.begin(), nums.end());
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] == target) {
				result.push_back(i);
			}
		}
		return result;
	}
};
//????????????????????????
class Solution {
public:
	double average(vector<int>& salary) {
		sort(salary.begin(), salary.end());
		deque<int> new_salary(salary.begin(), salary.end());
		new_salary.pop_front();
		new_salary.pop_back();
		double sum = 0.0;
		for (int i = 0; i < new_salary.size(); i++) {
			sum += new_salary[i];
		}
		return sum / new_salary.size();
	}
};
//??????????????x?????
class Solution {
public:
	bool checkXMatrix(vector<vector<int>>& grid) {
		for (int i = 0; i < grid.size(); i++) {
			for (int j = 0; j < grid[i].size(); j++) {
				if (i == j || i + j == grid.size() - 1) {
					if (grid[i][j] == 0) {
						return false;
					}
				}
				else {
					if (grid[i][j] != 0) {
						return false;
					}
				}
			}
		}
		return true;
	}
};
//????????????????
class Solution {
public:
	int findNumbers(vector<int>& nums) {
		int figure_count = 0;
		for (int i = 0; i < nums.size(); i++) {
			int count = 0;
			int temp = nums[i];
			while (temp) {
				count++;
				temp /= 10;
			}
			if (count % 2 == 0) {
				figure_count++;
			}
		}
		return figure_count;
	}
};
//???????????????
class Solution {
public:
	bool canMakeArithmeticProgression(vector<int>& arr) {
		vector<int> diff;
		sort(arr.begin(), arr.end());
		for (int i = 0; i < arr.size() - 1; i++) {
			diff.push_back(arr[i + 1] - arr[i]);
		}
		for (int i = 0; i < diff.size() - 1; i++) {
			if (diff[i + 1] != diff[i]) {
				return false;
			}
		}
		return true;
	}
};
//1051.???????
class Solution {
public:
	int heightChecker(vector<int>& heights) {
		vector<int> array;
		array = heights;
		sort(heights.begin(), heights.end());
		int count = 0;
		for (int i = 0; i < heights.size(); i++) {
			if (array[i] != heights[i]) {
				count++;
			}
		}
		return count;
	}
};
//200.??????????
class Solution {
public:
	void string_reverse(string& s, int left, int right) {
		while (left <= right) {
			char temp = s[left];
			s[left] = s[right];
			s[right] = temp;
			left++;
			right--;
		}
	}
	string reversePrefix(string word, char ch) {
		int i = 0;
		for (i = 0; i < word.size(); i++) {
			if (word[i] == ch) {
				break;
			}
		}
		if (i >= word.size()) {
			return word;
		}
		string_reverse(word, 0, i);
		return word;
	}
};
//??????VI
class Solution {
public:
	int trainingPlan(vector<int>& actions) {
		multimap<int, int> array;
		for (int i = 0; i < actions.size(); i++) {
			multimap<int, int> ::iterator it = array.find(actions[i]);
			if (it != array.end()) {
				it->second += 1;
			}
			else {
				array.insert(make_pair(actions[i], 1));
			}
		}
		for (multimap<int, int>::iterator it = array.begin(); it != array.end(); it++) {
			if (it->second == 1) {
				return it->first;
			}
		}
		return 0;
	}
};
class Solution {
public:
	vector<int> statisticalResult(vector<int>& arrayA) {
		vector<int> result;
		//???0?????
		int count_zero = 0;
		for (int i = 0; i < arrayA.size(); i++) {
			if (arrayA[i] == 0) {
				count_zero++;
			}
		}
		if (count_zero == 0) {
			//?????????
			int mul = 1;
			for (int i = 0; i < arrayA.size(); i++) {
				mul *= arrayA[i];
			}
			for (int i = 0; i < arrayA.size(); i++) {
				result.push_back(mul / arrayA[i]);
			}
		}
		else if (count_zero == 1) {
			//?????????
			int mul = 1;
			for (int i = 0; i < arrayA.size(); i++) {
				if (arrayA[i] != 0) {
					mul *= arrayA[i];
				}
			}
			for (int i = 0; i < arrayA.size(); i++) {
				if (arrayA[i] == 0) {
					result.push_back(mul);
				}
				else {
					result.push_back(0);
				}
			}
		}
		else {
			result.resize(arrayA.size(), 0);
		}
		return result;
	}
};
//LCR 184.??????????
class Checkout {
public:
	deque<int> array;
	Checkout() {
		array.clear();
	}
	//??????
	int get_max() {
		if (array.size() == 0) {
			return -1;
		}
		else {
			vector<int> temp(array.begin(), array.end());
			vector<int> ::iterator it = max_element(temp.begin(), temp.end());
			return *it;
		}
	}
	//???????
	void add(int value) {
		array.push_back(value);
	}
	//?????????
	int remove() {
		if (array.size() == 0) {
			return -1;
		}
		else {
			int temp = array[0];
			array.pop_front();
			return temp;
		}
	}
};

/**
 * Your Checkout object will be instantiated and called as such:
 * Checkout* obj = new Checkout();
 * int param_1 = obj->get_max();
 * obj->add(value);
 * int param_3 = obj->remove();
 */
 //919.???????????????
  /**
   * Definition for a binary tree node.
   * struct TreeNode {
   *     int val;
   *     TreeNode *left;
   *     TreeNode *right;
   *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
   *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
   *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
   * };
   */
class CBTInserter {
public:
	//?????????
	TreeNode* root_t;
	//?????????????????
	queue<TreeNode*> quence;
	CBTInserter(TreeNode* root) {
		root_t = root;
		//???????????????????? 
		quence.push(root);
	}

	int insert(int val) {
		//???????????
		int parent_value;
		while (quence.size() != 0) {
			TreeNode* temp = quence.front();
			//??????????????????????,?????????????????
			if (temp->left != NULL && temp->right != NULL) {
				quence.push(temp->left);
				quence.push(temp->right);
				quence.pop();
			}
			else {//???????????????????????????????????????????????
				if (temp->left == NULL) {
					temp->left = new TreeNode(val);
					parent_value = temp->val;
					break;
				}
				if (temp->right == NULL) {
					temp->right = new TreeNode(val);
					parent_value = temp->val;
					break;
				}
			}
		}
		return parent_value;
	}

	TreeNode* get_root() {
		//???????
		return root_t;
	}
};
//34.????????
/**
 * Your CBTInserter object will be instantiated and called as such:
 * CBTInserter* obj = new CBTInserter(root);
 * int param_1 = obj->insert(val);
 * TreeNode* param_2 = obj->get_root();
 */
class Solution {
public:
	vector<int> reset_array;
	vector<int> array;
	//????????????????????????
	Solution(vector<int>& nums) {
		reset_array = nums;
		array = nums;
		srand((unsigned)time(NULL));
	}
	//??????????
	vector<int> reset() {
		array = reset_array;
		return array;
	}
	//???random_shuffle????????
	vector<int> shuffle() {
		random_shuffle(array.begin(), array.end());
		return array;
	}
};

/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(nums);
 * vector<int> param_1 = obj->reset();
 * vector<int> param_2 = obj->shuffle();
 */
 //?????
class Solution {
public:
	int maximumGap(vector<int>& nums) {
		if (nums.size() < 2) {
			return 0;
		}
		sort(nums.begin(), nums.end());
		int max = 0;
		for (int i = 0; i < nums.size() - 1; i++) {
			if (nums[i + 1] - nums[i] > max) {
				max = nums[i + 1] - nums[i];
			}
		}
		return max;
	}
};
//1441.???????????????
class Solution {
public:
	vector<string> buildArray(vector<int>& target, int n) {
		int value = 1;
		int i = 0;
		vector<string> result;
		while (i < target.size()) {
			if (target[i] == value) {
				result.push_back("Push");
				i++;
			}
			else {
				result.push_back("Push");
				result.push_back("Pop");
			}
			value++;
		}
		return result;
	}
};
//151.????
class MinStack {
public:
	vector<int> array;
	//??????
	MinStack() {
		array.clear();
	}
	//???
	void push(int val) {
		array.push_back(val);
	}
	//??? 
	void pop() {
		array.pop_back();
	}
	//??????????
	int top() {
		return array[array.size() - 1];
	}
	//????????????
	int getMin() {
		vector<int> ::iterator it = min_element(array.begin(), array.end());
		return *it;
	}
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */
 //???K????????
class ProductOfNumbers {
public:
	vector<int> array;
	ProductOfNumbers() {
		array.clear();
	}

	void add(int num) {
		array.push_back(num);
	}

	int getProduct(int k) {
		int mul = 1;
		int count = 0;
		//??????????????
		int index = array.size() - 1;
		while (index >= 0) {
			mul *= array[index];
			index--;
			count++;
			if (count == k) {
				break;
			}
		}
		return mul;
	}
};

/**
 * Your ProductOfNumbers object will be instantiated and called as such:
 * ProductOfNumbers* obj = new ProductOfNumbers();
 * obj->add(num);
 * int param_2 = obj->getProduct(k);
 */
 //99.?????????????
  /**
   * Definition for a binary tree node.
   * struct TreeNode {
   *     int val;
   *     TreeNode *left;
   *     TreeNode *right;
   *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
   *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
   *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
   * };
   */
class Solution {
public:
	//???????????????????????????????
	void inorder_travel(TreeNode* root, vector<int>& nums) {
		if (root == NULL) {
			return;
		}
		inorder_travel(root->left, nums);
		nums.push_back(root->val);
		inorder_travel(root->right, nums);
	}
	//????????????????????????????????????
	void inorder_travel_assign(TreeNode* root, vector<int>& nums, int& index) {
		if (root == NULL) {
			return;
		}
		inorder_travel_assign(root->left, nums, index);
		root->val = nums[index];
		index++;
		inorder_travel_assign(root->right, nums, index);
	}
	void recoverTree(TreeNode* root) {
		vector<int> array;
		//????????????
		inorder_travel(root, array);
		//?????????????
		sort(array.begin(), array.end());
		int i = 0;
		//????????????
		inorder_travel_assign(root, array, i);
	}
};
//?????
class SortedStack {
public:
	vector<int> stack_array;
	SortedStack() {
		stack_array.clear();
	}

	void push(int val) {
		if (stack_array.size() == 0) {
			stack_array.push_back(val);
		}
		else {
			//??????????????????????????????????????
			if (stack_array[stack_array.size() - 1] >= val) {
				stack_array.push_back(val);
			}
			else {
				//???????????????????????????????????????????????
				int i = 0;
				for (i = 0; i < stack_array.size(); i++) {
					if (stack_array[i] < val) {
						break;
					}
				}
				stack_array.insert(stack_array.begin() + i, val);
			}
		}
	}

	void pop() {
		if (stack_array.size() == 0) {
			return;
		}
		stack_array.pop_back();
	}

	int peek() {
		if (stack_array.size() == 0) {
			return -1;
		}
		else {
			return stack_array[stack_array.size() - 1];
		}
	}

	bool isEmpty() {
		if (stack_array.size() == 0) {
			return true;
		}
		else {
			return false;
		}

	}
};

/**
 * Your SortedStack object will be instantiated and called as such:
 * SortedStack* obj = new SortedStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->isEmpty();
 */
 //????????d??
class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	//?????????
	void allpaths(vector<vector<int>>& graph, int v_index) {
		if (v_index == graph.size() - 1) {
			result.push_back(array);
			return;
		}
		for (int j = 0; j < graph[v_index].size(); j++) {
			int index = graph[v_index][j];
			array.push_back(index);
			allpaths(graph, index);
			//???????
			array.pop_back();
		}
	}
	vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
		//??????????
		int v_index = 0;
		//?????????0?????????????????0??????????
		array.push_back(v_index);
		allpaths(graph, v_index);
		return result;
	}
};
//841.???????
class Solution {
public:
	void VisitAllRooms(int v_index, vector<vector<int>>& rooms, vector<bool>& visited) {
		//???????????????????
		visited[v_index] = true;
		for (int j = 0; j < rooms[v_index].size(); j++) {
			//????????????????????????????
			if (visited[rooms[v_index][j]] != true) {
				int index = rooms[v_index][j];
				VisitAllRooms(index, rooms, visited);
			}
		}
	}
	bool canVisitAllRooms(vector<vector<int>>& rooms) {
		//?????????????????????????????
		vector<bool> visited;
		visited.resize(rooms.size(), false);
		int v_index = 0;
		//??????????????
		VisitAllRooms(v_index, rooms, visited);
		for (int i = 0; i < visited.size(); i++) {
			if (visited[i] == false) {
				return false;
			}
		}
		return true;
	}
};
//???????????
class Solution {
public:
	int edgeScore(vector<int>& edges) {
		//??map????????????????????????????
		map<int, long long> edge;
		for (int i = 0; i < edges.size(); i++) {
			map<int, long long> ::iterator it = edge.find(edges[i]);
			if (it != edge.end()) {
				it->second += i;
			}
			else {
				edge.insert(make_pair(edges[i], i));
			}
		}
		vector<int> max_number;
		long long max = 0;
		int flag = 1;
		//??????????????
		for (map<int, long long> ::iterator it = edge.begin(); it != edge.end(); it++) {
			if (flag == 1) {
				max = it->second;
				max_number.push_back(it->first);
				flag = 0;
			}
			else {
				if (it->second > max) {
					max = it->second;
					max_number.clear();
					max_number.push_back(it->first);
				}
			}
		}
		sort(max_number.begin(), max_number.end());
		return max_number[0];
	}
};
//???d??
class Solution {
public:
	int uniquePaths(int m, int n) {
		//????dp????
		vector<vector<int>> dp;
		dp.resize(m);
		for (int i = 0; i < dp.size(); i++) {
			dp[i].resize(n);
		}
		//???dp????????
		//?????
		for (int j = 0; j < dp[0].size(); j++) {
			dp[0][j] = 1;
		}
		for (int i = 0; i < dp.size(); i++) {
			dp[i][0] = 1;
		}
		//??????????
		for (int i = 1; i < m; i++) {
			for (int j = 1; j < n; j++) {
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			}
		}
		return dp[m - 1][n - 1];
	}
};
//???d??||
class Solution {
public:
	int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
		//????dp????????
		vector<vector<int>> dp;
		dp.resize(obstacleGrid.size());
		for (int i = 0; i < dp.size(); i++) {
			dp[i].resize(obstacleGrid[i].size());
		}
		//1.dp???????????
		//2.??????
		//3.?????
		//???????????
		int j = 0;
		for (j = 0; j < dp[0].size(); j++) {
			if (obstacleGrid[0][j] != 1) {
				dp[0][j] = 1;
			}
			else {
				break;
			}
		}
		while (j < dp[0].size()) {
			dp[0][j] = 0;
			j++;
		}
		int i = 0;
		for (i = 0; i < dp.size(); i++) {
			if (obstacleGrid[i][0] != 1) {
				dp[i][0] = 1;
			}
			else {
				break;
			}
		}
		while (i < dp.size()) {
			dp[i][0] = 0;
			i++;
		}
		//??????????
		for (i = 1; i < dp.size(); i++) {
			for (j = 1; j < dp[i].size(); j++) {
				if (obstacleGrid[i][j] == 1) {
					dp[i][j] = 0;
					continue;
				}
				else {
					dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				}
			}
		}
		return dp[dp.size() - 1][dp[0].size() - 1];
	}
};
//???????????
class Solution {
public:
	bool isStrictlyPalindromic(int n) {
		return false;
	}
};
//????????????
class Solution {
public:
	string printBin(double num) {
		string result;
		double compare_value = 1.0;
		result.push_back('0');
		result.push_back('.');
		while (result.size() <= 33) {
			num *= 2;
			int temp = num;
			result.push_back(temp + '0');
			if (num > 1.0) {
				num -= 1.0;
			}
			else if (num == 1.0) {
				break;
			}
		}
		if (result.size() > 32) {
			string result1 = "ERROR";
			return result1;
		}
		else {
			return result;
		}
	}
};
//?????????????
class Solution {
public:
	vector<int> processQueries(vector<int>& queries, int m) {
		vector<int> result;
		//????p????
		vector<int> array;
		array.resize(m);
		for (int i = 0; i < array.size(); i++) {
			array[i] = i + 1;
		}
		//????queries????
		for (int i = 0; i < queries.size(); i++) {
			//???????????????
			int num = queries[i];
			int index = 0;
			//?????array?????????queries?????
			for (; index < array.size(); index++) {
				if (array[index] == num) {
					break;
				}
			}
			//?????????????result??????
			result.push_back(index);
			//array???????????????????
			array.erase(array.begin() + index);
			array.insert(array.begin(), num);
		}
		return result;
	}
};
//1877.??????????????????????
class Solution {
public:
	int minPairSum(vector<int>& nums) {
		//??????
		sort(nums.begin(), nums.end());
		vector<int> pair_sum;
		int left = 0;
		int right = nums.size() - 1;
		//???????????????
		while (left < right) {
			int sum = nums[left] + nums[right];
			pair_sum.push_back(sum);
			left++;
			right--;
		}
		//?????????????????
		vector<int> ::iterator it = max_element(pair_sum.begin(), pair_sum.end());
		return *it;
	}
};
//?????????
class Solution {
public:
	bool isvalid(vector<vector<char>>& board, char num, int row, int col) {
		//?????????
		int leftrow = row - 1;
		while (leftrow >= 0) {
			if (board[leftrow][col] == num) {
				return false;
			}
			leftrow--;
		}
		//?????????
		int rightrow = row + 1;
		while (rightrow < 9) {
			if (board[rightrow][col] == num) {
				return false;
			}
			rightrow++;
		}
		//?????????
		int upcol = col - 1;
		while (upcol >= 0) {
			if (board[row][upcol] == num) {
				return false;
			}
			upcol--;
		}
		//?????????
		int downcol = col + 1;
		while (downcol < 9) {
			if (board[row][downcol] == num) {
				return false;
			}
			downcol++;
		}
		//?????jiu'gong'ge
		int part_row = row;
		while (part_row != 0 && part_row != 3 && part_row != 6) {
			part_row--;
		}
		int part_col = col;
		while (part_col != 0 && part_col != 3 && part_col != 6) {
			part_col--;
		}
		for (int i = part_row; i <= part_row + 2; i++) {
			for (int j = part_col; j <= part_col + 2; j++) {
				if (board[i][j] != '.' && i != row && j != col) {
					if (board[i][j] == num) {
						return false;
					}
				}
			}
		}
		return true;
	}
	bool isValidSudoku(vector<vector<char>>& board) {
		for (int i = 0; i < board.size(); i++) {
			for (int j = 0; j < board[i].size(); j++) {
				if (board[i][j] != '.') {
					bool ret = isvalid(board, board[i][j], i, j);
					if (ret == false) {
						return false;
					}
				}
			}
		}
		return true;
	}
};
//3195.????????1????????????I
class Solution {
public:
	int minimumArea(vector<vector<int>>& grid) {
		//??????????
		deque<deque<int>> row_distance;
		for (int i = 0; i < grid.size(); i++) {
			//???????????????1?????????1????????????
			deque<int> array;
			array.clear();
			int left = 0;
			int right = grid[i].size() - 1;
			while (left < grid[i].size() && grid[i][left] != 1) {
				left++;
			}
			if (left < grid[i].size()) {
				array.push_back(left);
			}
			while (right >= 0 && grid[i][right] != 1) {
				right--;
			}
			//???????????????????0
			if (right >= 0) {
				array.push_back(right);
			}
			row_distance.push_back(array);
		}
		//?????????????????0?????
		while (row_distance[0].size() == 0) {
			row_distance.pop_front();
		}
		//?????????????????0?????
		while (row_distance[row_distance.size() - 1].size() == 0) {
			row_distance.pop_back();
		}
		//??????????????????1
		//??????????????????????????????       
		int minwidth = 0;
		int maxwidth = 0;
		int flag = 1;
		for (int i = 0; i < row_distance.size(); i++) {
			for (int j = 0; j < row_distance[i].size(); j++) {
				if (flag == 1) {
					minwidth = row_distance[i][j];
					maxwidth = row_distance[i][j];
					flag = 0;
				}
				else {
					if (row_distance[i][j] < minwidth) {
						minwidth = row_distance[i][j];
					}
					if (row_distance[i][j] > maxwidth) {
						maxwidth = row_distance[i][j];
					}
				}
			}
		}
		//??????
		return row_distance.size() * (maxwidth - minwidth + 1);
	}
};
class Solution {
public:
	int findPermutationDifference(string s, string t) {
		int sum = 0;
		int i = 0;
		map<char, int> char_index;
		for (int i = 0; i < s.size(); i++) {
			char_index.insert(make_pair(s[i], i));
		}
		for (int i = 0; i < t.size(); i++) {
			map<char, int> ::iterator it = char_index.find(t[i]);
			sum += abs(it->second - i);
		}
		return sum;
	}
};
// ????????????
class Solution {
public:
	vector<int> arrayChange(vector<int>& nums, vector<vector<int>>& operations) {
		map<int, int> element_index;
		//???????????????????????
		for (int i = 0; i < nums.size(); i++) {
			element_index.insert(make_pair(nums[i], i));
		}
		//????map??????????????????
		for (int i = 0; i < operations.size(); i++) {
			map<int, int> ::iterator it = element_index.find(operations[i][0]);
			//??????
			nums[it->second] = operations[i][1];
			//?????????????????map??????
			element_index.insert(make_pair(operations[i][1], it->second));
			//???????????
			element_index.erase(it);
		}
		return nums;
	}
};
//????????????
class Solution {
public:
	int integerBreak(int n) {
		//?????dp????
		vector<int> dp;
		//1.???dp????????
		//2.???dp???????
		//3.?????dp????
		//4.???????
		dp.resize(n + 1);
		dp[0] = 0;
		dp[1] = 0;
		dp[2] = 1;
		for (int i = 3; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				vector<int> array;
				array.push_back(j * (i - j));
				array.push_back(j * dp[i - j]);
				array.push_back(dp[i]);
				vector<int> ::iterator it = max_element(array.begin(), array.end());
				dp[i] = *it;
			}
		}
		return dp[n];
	}
};
//???????
class Solution {
public:
	int integerBreak(int n) {
		//?????dp????
		vector<int> dp;
		//1.???dp????????
		//2.???dp???????
		//3.?????dp????
		//4.???????
		dp.resize(n + 1);
		dp[0] = 0;
		dp[1] = 0;
		dp[2] = 1;
		for (int i = 3; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				vector<int> array;
				array.push_back(j * (i - j));
				array.push_back(j * dp[i - j]);
				array.push_back(dp[i]);
				vector<int> ::iterator it = max_element(array.begin(), array.end());
				dp[i] = *it;
			}
		}
		return dp[n];
	}
}
//??????????????
class Solution {
public:
	int numTrees(int n) {
		//????dp????
		//???dp???????
		//??????
		//?????
		//??????????
		//???dp????
		if (n == 1) {
			return 1;
		}
		if (n == 2) {
			return 2;
		}
		//????dp????
		vector<int> dp;
		//??dp?????????????
		dp.resize(n + 1, 0);
		dp[0] = 1;
		dp[1] = 1;
		dp[2] = 2;
		for (int i = 3; i <= n; i++) {
			int j = 1;
			while (j <= i) {
				dp[i] += (dp[j - 1] * dp[i - j]);
				j++;
			}
		}
		return dp[n];
	}
};
//????????????
class Solution {
public:
	vector<int> stableMountains(vector<int>& height, int threshold) {
		vector<int> result;
		for (int i = 1; i < height.size(); i++) {
			if (height[i - 1] > threshold) {
				result.push_back(i);
			}
		}
		return result;
	}
};
//????????
class Solution {
public:
	bool isArraySpecial(vector<int>& nums) {
		if (nums.size() == 1) {
			return true;
		}
		if (nums.size() == 2) {
			if (nums[0] % 2 == 0 && nums[1] % 2 == 0) {
				return false;
			}
			if (nums[0] % 2 != 0 && nums[1] % 2 != 0) {
				return false;
			}
		}
		else {
			for (int i = 1; i < nums.size() - 1; i++) {
				int number1 = nums[i - 1];
				int number2 = nums[i + 1];
				if (nums[i] % 2 == 0) {
					if (number1 % 2 == 0) {
						return false;
					}
					if (number2 % 2 == 0) {
						return false;
					}
				}
				else {
					if (number1 % 2 != 0) {
						return false;
					}
					if (number2 % 2 != 0) {
						return false;
					}
				}
			}
		}
		return true;
	}
};
//???????????????
class Solution {
public:
	vector<int> buildArray(vector<int>& nums) {
		vector<int> result;
		for (int i = 0; i < nums.size(); i++) {
			result.push_back(nums[nums[i]]);
		}
		return result;
	}
};
//???????????????????
class Solution {
public:
	vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
		vector<int> result;
		for (int i = 0; i < nums.size(); i++) {
			int frontindex = i - 1;
			int count = 0;
			int backindex = i + 1;
			while (frontindex >= 0) {
				if (nums[frontindex] < nums[i]) {
					count++;
				}
				frontindex--;
			}
			while (backindex < nums.size()) {
				if (nums[backindex] < nums[i]) {
					count++;
				}
				backindex++;
			}
			result.push_back(count);
		}
		return result;
	}
};
//3033.??????
class Solution {
public:
	vector<vector<int>> modifiedMatrix(vector<vector<int>>& matrix) {
		vector<int> max_array;
		vector<vector<int>> result;
		int row = matrix.size();
		int col = matrix[0].size();
		for (int j = 0; j < col; j++) {
			int max = matrix[0][j];
			for (int i = 1; i < row; i++) {
				if (max < matrix[i][j]) {
					max = matrix[i][j];
				}
			}
			max_array.push_back(max);
		}
		for (int j = 0; j < col; j++) {
			for (int i = 0; i < row; i++) {
				if (matrix[i][j] == -1) {
					matrix[i][j] = max_array[j];
				}
			}
		}
		return matrix;
	}
};
//??????:???????
class WordsFrequency {
public:
	map<string, int> word_count;
	WordsFrequency(vector<string>& book) {
		for (int i = 0; i < book.size(); i++) {
			map<string, int> ::iterator it = word_count.find(book[i]);
			if (it != word_count.end()) {
				it->second += 1;
			}
			else {
				word_count.insert(make_pair(book[i], 1));
			}
		}
	}

	int get(string word) {
		map<string, int> ::iterator it = word_count.find(word);
		if (it != word_count.end()) {
			return it->second;
		}
		else {
			return 0;
		}
	}
};
//??????????
/**
 * Your WordsFrequency object will be instantiated and called as such:
 * WordsFrequency* obj = new WordsFrequency(book);
 * int param_1 = obj->get(word);
 */
class FrontMiddleBackQueue {
public:
	deque<int> array;
	FrontMiddleBackQueue() {
		array.clear();
	}
	//????????
	void pushFront(int val) {
		array.push_front(val);
	}
	//???????
	void pushMiddle(int val) {
		if (array.size() == 0) {
			array.push_back(val);
		}
		else {
			int index = (0 + (array.size() - 1)) / 2;
			if (array.size() % 2 == 0) {
				array.insert(array.begin() + index + 1, val);
			}
			else {
				array.insert(array.begin() + index, val);
			}
		}
	}
	//???????
	void pushBack(int val) {
		array.push_back(val);
	}
	//???
	int popFront() {
		if (array.size() != 0) {
			int front_element = array.front();
			array.pop_front();
			return front_element;
		}
		else {
			return -1;
		}
	}
	//?????
	int popMiddle() {
		if (array.size() != 0) {
			int index = (0 + array.size() - 1) / 2;
			int mid_element = array[index];
			array.erase(array.begin() + index);
			return mid_element;
		}
		else {
			return -1;
		}
	}
	//?????
	int popBack() {
		if (array.size() != 0) {
			int back_element = array.back();
			array.pop_back();
			return back_element;
		}
		else {
			return -1;
		}
	}
};
//??????????????
/**
 * Your FrontMiddleBackQueue object will be instantiated and called as such:
 * FrontMiddleBackQueue* obj = new FrontMiddleBackQueue();
 * obj->pushFront(val);
 * obj->pushMiddle(val);
 * obj->pushBack(val);
 * int param_4 = obj->popFront();
 * int param_5 = obj->popMiddle();
 * int param_6 = obj->popBack();
 */
class SmallestInfiniteSet {
public:
	set<int> array;
	SmallestInfiniteSet() {
		for (int i = 1; i <= 1000; i++) {
			array.insert(i);
		}
	}

	int popSmallest() {
		set<int> ::iterator it = array.begin();
		int num = *it;
		array.erase(it);
		return num;
	}

	void addBack(int num) {
		set<int> ::iterator it = array.find(num);
		if (it == array.end()) {
			array.insert(num);
		}
	}
};
//?????????????????
/**
 * Your SmallestInfiniteSet object will be instantiated and called as such:
 * SmallestInfiniteSet* obj = new SmallestInfiniteSet();
 * int param_1 = obj->popSmallest();
 * obj->addBack(num);
 */
 /**
  * Definition for singly-linked list.
  * struct ListNode {
  *     int val;
  *     ListNode *next;
  *     ListNode() : val(0), next(nullptr) {}
  *     ListNode(int x) : val(x), next(nullptr) {}
  *     ListNode(int x, ListNode *next) : val(x), next(next) {}
  * };
  */
class Solution {
public:
	ListNode* insertGreatestCommonDivisors(ListNode* head) {
		ListNode* cur = head;
		while (cur->next != NULL) {
			int curval = cur->val;
			int nextval = cur->next->val;
			int common_Divisors = __gcd(curval, nextval);
			ListNode* newnode = new ListNode(common_Divisors);
			newnode->next = cur->next;
			cur->next = newnode;
			cur = cur->next;
			cur = cur->next;
		}
		return head;
	}
};
//1315.???????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	int sumEvenGrandparent(TreeNode* root) {
		//??????????? 
		queue<TreeNode*> enquence;
		int count = 1;
		vector<int> grandchildren;
		enquence.push(root);
		while (!enquence.empty()) {
			TreeNode* temp = enquence.front();
			if (temp->val % 2 == 0) {
				//???temp????????????????????????
				queue<TreeNode*> temp_queue;
				int height = 1;
				int count = 1;
				int nextcount = 0;
				temp_queue.push(temp);
				while (!temp_queue.empty() && height != 4) {
					for (int i = 0; i < count; i++) {
						TreeNode* temp_node = temp_queue.front();
						if (height == 3) {
							grandchildren.push_back(temp_node->val);
						}
						if (temp_node->left != NULL) {
							temp_queue.push(temp_node->left);
							nextcount++;
						}
						if (temp_node->right != NULL) {
							temp_queue.push(temp_node->right);
							nextcount++;
						}
						temp_queue.pop();
					}
					height++;
					count = nextcount;
					nextcount = 0;
				}
			}
			if (temp->left != NULL) {
				enquence.push(temp->left);
			}
			if (temp->right != NULL) {
				enquence.push(temp->right);
			}
			enquence.pop();
		}
		int sum = 0;
		for (int i = 0; i < grandchildren.size(); i++) {
			sum += grandchildren[i];
		}
		return sum;
	}
};
//???k??????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
	ListNode* mergeKLists(vector<ListNode*>& lists) {
		//????????
		vector<int> sort_array;
		//???????????????????????
		for (int i = 0; i < lists.size(); i++) {
			ListNode* cur = lists[i];
			while (cur) {
				sort_array.push_back(cur->val);
				cur = cur->next;
			}
		}
		//???????????????NULL
		if (sort_array.size() == 0) {
			return NULL;
		}
		else {
			//????????????????????????????
			ListNode* head = NULL;
			ListNode* p = NULL;
			//???????????
			sort(sort_array.begin(), sort_array.end());
			for (int i = 0; i < sort_array.size(); i++) {
				if (head == NULL) {
					ListNode* newnode = new ListNode(sort_array[i]);
					head = newnode;
					p = head;
				}
				else {
					ListNode* newnode = new ListNode(sort_array[i]);
					newnode->next = p->next;
					p->next = newnode;
					p = newnode;
				}
			}
			return head;
		}
	}
};
//????????II
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
	ListNode* detectCycle(ListNode* head) {
		//multiset???????????????
		multiset<ListNode*> array;
		//????????????????
		ListNode* cur = head;
		//???????
		while (cur) {
			array.insert(cur);
			multiset<ListNode*> ::iterator it = array.find(cur->next);
			//???cur->next??????array???????????????????cur????????
			if (it != array.end()) {
				return cur->next;
			}
			cur = cur->next;
		}
		return NULL;
	}
};
//????????????????
class Solution {
public:
	int findPermutationDifference(string s, string t) {
		int sum = 0;
		int i = 0;
		map<char, int> char_index;
		for (int i = 0; i < s.size(); i++) {
			char_index.insert(make_pair(s[i], i));
		}
		for (int i = 0; i < t.size(); i++) {
			map<char, int> ::iterator it = char_index.find(t[i]);
			sum += abs(it->second - i);
		}
		return sum;
	}
}; class Solution {
public:
	int findPermutationDifference(string s, string t) {
		int sum = 0;
		int i = 0;
		map<char, int> char_index;
		for (int i = 0; i < s.size(); i++) {
			char_index.insert(make_pair(s[i], i));
		}
		for (int i = 0; i < t.size(); i++) {
			map<char, int> ::iterator it = char_index.find(t[i]);
			sum += abs(it->second - i);
		}
		return sum;
	}
};
//????????????????
class Solution {
public:
	int findPermutationDifference(string s, string t) {
		int sum = 0;
		int i = 0;
		map<char, int> char_index;
		for (int i = 0; i < s.size(); i++) {
			char_index.insert(make_pair(s[i], i));
		}
		for (int i = 0; i < t.size(); i++) {
			map<char, int> ::iterator it = char_index.find(t[i]);
			sum += abs(it->second - i);
		}
		return sum;
	}
};
//3271.??????????
class Solution {
public:
	string stringHash(string s, int k) {
		string result;
		int i = 0;
		int frequency = s.size() / k;
		int j = 0;
		while (j < frequency) {
			int count = 0;
			int sum = 0;
			while (count != k) {
				sum += (s[i] - 'a');
				count++;
				i++;
			}
			result.push_back('a' + sum % 26);
			j++;
		}
		return result;
	}
};
//?????????????????
class Solution {
public:
	int addedInteger(vector<int>& nums1, vector<int>& nums2) {
		sort(nums1.begin(), nums1.end());
		sort(nums2.begin(), nums2.end());
		int ret = nums2[0] - nums1[0];
		return ret;
	}
};
//???????????
class Solution {
public:
	vector<string> result;
	void  backtricking(int startindex, string& s) {
		result.push_back(s);
		for (int i = startindex; i < s.size(); i++) {
			if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) {
				if (s[i] >= 'a' && s[i] <= 'z') {
					s[i] -= 32;
					backtricking(i + 1, s);
					s[i] += 32;
				}
				else {
					s[i] += 32;
					backtricking(i + 1, s);
					s[i] -= 32;
				}
			}
		}
	}
	vector<string> letterCasePermutation(string s) {
		int startindex = 0;
		backtricking(startindex, s);
		return result;
	}
};
//????????????
class Solution {
public:
	int smallestEqual(vector<int>& nums) {
		for (int i = 0; i < nums.size(); i++) {
			if ((i % 10) == nums[i]) {
				return i;
			}
		}
		return -1;
	}
};
//????????????
class Solution {
public:
	vector<int> runningSum(vector<int>& nums) {
		vector<int> result;
		result.push_back(nums[0]);
		int sum = nums[0];
		for (int i = 1; i < nums.size(); i++) {
			sum += nums[i];
			result.push_back(sum);
		}
		return result;
	}
};
//???????????????
class Solution {
public:
	int maximumWealth(vector<vector<int>>& accounts) {
		vector<int> result;
		int sum = 0;
		for (int i = 0; i < accounts.size(); i++) {
			sum = 0;
			for (int j = 0; j < accounts[i].size(); j++) {
				sum += accounts[i][j];
			}
			result.push_back(sum);
		}
		vector<int> ::iterator it = max_element(result.begin(), result.end());
		return *it;
	}
};
//?????????
bool isValid(char* s) {
	if (s == NULL) {
		return false;
	}
	char* p = (char*)malloc(sizeof(char) * (strlen(s) + 1));
	int top = -1;
	for (int i = 0; s[i] != '\0'; i++) {
		if (s[i] == '(' || s[i] == '[' || s[i] == '{') {
			top++;
			p[top] = s[i];
		}
		else if ((top > -1) && ((p[top] == '(' && s[i] == ')') || (p[top] == '[' && s[i] == ']') || (p[top] == '{' && s[i] == '}'))) {
			top--;
		}
		else {
			return false;
		}
	}
	if (top == -1) {
		return true;
	}
	return false;
}
//3300??????????????????
class Solution {
public:
	int minElement(vector<int>& nums) {
		int bit_sum = 0;
		int flag = 1;
		for (int i = 0; i < nums.size(); i++) {
			int num = nums[i];
			int sum = 0;
			while (num) {
				sum += (num % 10);
				num /= 10;
			}
			if (flag == 1) {
				bit_sum = sum;
				flag = 0;
			}
			else {
				if (sum < bit_sum) {
					bit_sum = sum;
				}
			}
		}
		return bit_sum;
	}
};
//1860.??????????
class Solution {
public:
	vector<int> memLeak(int memory1, int memory2) {
		vector<int> result;
		int increase_memory = 1;
		while (1) {
			if (memory1 < increase_memory && memory2 < increase_memory) {
				break;
			}
			if (memory1 > memory2) {
				memory1 -= increase_memory;
			}
			else if (memory1 < memory2) {
				memory2 -= increase_memory;
			}
			else {
				memory1 -= increase_memory;
			}
			increase_memory++;
		}
		result.push_back(increase_memory);
		result.push_back(memory1);
		result.push_back(memory2);
		return result;
	}
};
//?????????????
class Solution {
public:
	string toHex(int num) {
		string result;
		//??????????????
		unsigned int number = num;
		//????????????????????

		while (number) {
			int temp = number % 16;
			if (temp > 9) {
				result.push_back(temp - 10 + 'a');
			}
			else {
				result.push_back(temp + '0');
			}
			number /= 16;
		}
		if (result.size() == 0) {
			result.push_back('0');
		}
		reverse(result.begin(), result.end());
		return result;
	}
};
//????????????????????? 
class Solution {
public:
	int maxProductDifference(vector<int>& nums) {
		sort(nums.begin(), nums.end());
		int length = nums.size() - 1;
		return nums[length] * nums[length - 1] - nums[0] * nums[1];
	}
};
//???????
class Solution {
public:
	string clearDigits(string s) {
		for (int i = 0; i < s.size(); i++) {
			if (s[i] >= '0' && s[i] <= '9') {
				s.erase(s.begin() + i);
				s.erase(s.begin() + i - 1);
				i -= 2;
			}
		}
		return s;
	}
};
//???????????
class Solution {
public:
	bool isBalanced(string num) {
		int sum_odds = 0;
		int sum_even = 0;
		for (int i = 0; i < num.size(); i++) {
			if (i % 2 == 0) {
				sum_odds += num[i] - '0';
			}
			else {
				sum_even += num[i] - '0';
			}
		}
		if (sum_odds == sum_even) {
			return true;
		}
		else {
			return false;
		}
	}
};
//3005.?????????
class Solution {
public:
	int maxFrequencyElements(vector<int>& nums) {
		map<int, int> array;
		for (int i = 0; i < nums.size(); i++) {
			map<int, int> ::iterator it = array.find(nums[i]);
			if (it != array.end()) {
				it->second += 1;
			}
			else {
				array.insert(make_pair(nums[i], 1));
			}
		}
		int max = 0;
		for (map<int, int> ::iterator it = array.begin(); it != array.end(); it++) {
			if (it->second > max) {
				max = it->second;
			}
		}
		int count = 0;
		for (map<int, int> ::iterator it = array.begin(); it != array.end(); it++) {
			if (it->second == max) {
				count += it->second;
			}
		}
		return count;
	}
};
//??????????????????
class Solution {
public:
	int minElement(vector<int>& nums) {
		int bit_sum = 0;
		int flag = 1;
		for (int i = 0; i < nums.size(); i++) {
			int num = nums[i];
			int sum = 0;
			while (num) {
				sum += (num % 10);
				num /= 10;
			}
			if (flag == 1) {
				bit_sum = sum;
				flag = 0;
			}
			else {
				if (sum < bit_sum) {
					bit_sum = sum;
				}
			}
		}
		return bit_sum;
	}
};
//???????
class Solution {
public:
	string clearDigits(string s) {
		for (int i = 0; i < s.size(); i++) {
			if (s[i] >= '0' && s[i] <= '9') {
				s.erase(s.begin() + i);
				s.erase(s.begin() + i - 1);
				i -= 2;
			}
		}
		return s;
	}
};
//2108.??????????????????????
class Solution {
public:
	bool Is_Vaild_Palindrome(string str) {
		int left = 0;
		int right = str.size() - 1;
		while (left <= right) {
			if (str[left] != str[right]) {
				return false;
			}
			left++;
			right--;
		}
		return true;
	}
	string firstPalindrome(vector<string>& words) {
		string result;
		for (int i = 0; i < words.size(); i++) {
			bool ret = Is_Vaild_Palindrome(words[i]);
			if (ret == true) {
				result = words[i];
				break;
			}
		}
		return result;
	}
};
//??????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	void Preorder_travel(TreeNode* root, vector<int>& array) {
		if (root == NULL) {
			return;
		}
		if (root->left == NULL && root->right == NULL) {
			array.push_back(root->val);
		}
		Preorder_travel(root->left, array);
		Preorder_travel(root->right, array);
	}
	bool leafSimilar(TreeNode* root1, TreeNode* root2) {
		vector<int> temp;
		vector<int> array1;
		vector<int> array2;
		Preorder_travel(root1, temp);
		array1 = temp;
		temp.clear();
		Preorder_travel(root2, temp);
		array2 = temp;
		if (array1.size() != array2.size()) {
			return false;
		}
		else {
			for (int i = 0; i < array1.size(); i++) {
				if (array1[i] != array2[i]) {
					return false;
				}
			}
			return true;
		}
	}
};
//????????
class Solution {
public:
	int smallestEvenMultiple(int n) {
		if (n % 2 == 0) {
			return 2 * 1 * (n / 2);
		}
		else {
			return n * 2;
		}
	}
};
//????K??????????????
class Solution {
public:
	int sumIndicesWithKSetBits(vector<int>& nums, int k) {
		int sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			int count = 0;
			int index = i;
			while (index) {
				if (index % 2 == 1) {
					count++;
				}
				index /= 2;
			}
			if (count == k) {
				sum += nums[i];
			}
		}
		return sum;
	}
};
//1347.??????????????????????
class Solution {
public:
	int minSteps(string s, string t) {
		string temp_s;
		string temp_t;
		temp_s = s;
		temp_t = t;
		sort(temp_s.begin(), temp_s.end());
		sort(temp_t.begin(), temp_t.end());
		string dest;
		set_intersection(temp_s.begin(), temp_s.end(), temp_t.begin(), temp_t.end(), back_inserter(dest));
		if (temp_s.compare(temp_t) == 0) {
			return 0;
		}
		else {
			return s.size() - dest.size();
		}
	}
};
//143.????????
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
	void reorderList(ListNode* head) {
		vector<ListNode*> array_node;
		ListNode* cur = head;
		//??????????????
		while (cur) {
			array_node.push_back(cur);
			cur = cur->next;
		}
		int left = 1;
		int right = array_node.size() - 1;
		ListNode* p = head;
		//????while????????????????????????
		while (left <= right) {
			if (array_node[left] == array_node[right]) {
				p->next = array_node[left];
				p = array_node[left];
				break;
			}
			else {
				p->next = array_node[right];
				p = array_node[right];
				p->next = array_node[left];
				p = array_node[left];
				left++;
				right--;
			}
		}
		p->next = NULL;
	}
};
//????????????2
class Solution {
public:
	int findFinalValue(vector<int>& nums, int original) {
		set<int> array;
		//???????????????set??????
		for (int i = 0; i < nums.size(); i++) {
			array.insert(nums[i]);
		}
		while (1) {
			set<int> ::iterator it = array.find(original);
			if (it != array.end()) {
				original *= 2;
			}
			else {
				break;
			}
		}
		return original;
	}
};
//1287.????????????????????25%?????
class Solution {
public:
	int findSpecialInteger(vector<int>& arr) {
		if (arr.size() == 1) {
			return arr[0];
		}
		map<int, int> array;
		for (int i = 0; i < arr.size(); i++) {
			map<int, int> ::iterator it = array.find(arr[i]);
			if (it != array.end()) {
				it->second += 1;
				if (it->second > (arr.size() / 4)) {
					return it->first;
				}
			}
			else {
				array.insert(make_pair(arr[i], 1));

			}
			if (it->second > (arr.size() / 4)) {
				return it->first;
			}
		}
		return 1;
	}
};
//1475.??????????????
class Solution {
public:
	vector<int> finalPrices(vector<int>& prices) {
		for (int i = 0; i < prices.size() - 1; i++) {
			for (int j = i + 1; j < prices.size(); j++) {
				if (prices[j] <= prices[i]) {
					prices[i] -= prices[j];
					break;
				}
			}
		}
		return prices;
	}
};
//?????????????||
class Solution {
public:
	int singleNumber(vector<int>& nums) {
		map<int, int> array;
		for (int i = 0; i < nums.size(); i++) {
			map<int, int>::iterator it = array.find(nums[i]);
			if (it != array.end()) {
				it->second += 1;
			}
			else {
				array.insert(make_pair(nums[i], 1));
			}
		}
		for (map<int, int> ::iterator it = array.begin(); it != array.end(); it++) {
			if (it->second == 1) {
				return it->first;
			}
		}
		return 1;
	}
};
//2399.???????????????
class Solution {
public:
	bool checkDistances(string s, vector<int>& distance) {
		map<char, int>  str_dist;
		for (int i = 0; i < s.size(); i++) {
			map<char, int> ::iterator it = str_dist.find(s[i]);
			if (it != str_dist.end()) {
				int dist = i - it->second - 1;
				cout << dist << endl;
				if (dist != distance[s[i] - 'a']) {
					return false;
				}
			}
			else {
				str_dist.insert(make_pair(s[i], i));
			}
		}
		return true;
	}
};
//2351.????????????????
class Solution {
public:
	char repeatedCharacter(string s) {
		set<char> str;
		for (int i = 0; i < s.size(); i++) {
			set<char> ::iterator it = str.find(s[i]);
			if (it != str.end()) {
				return *it;
			}
			else {
				str.insert(s[i]);
			}
		}
		char a = 'd';
		return a;
	}
};
//????????k????????
class Solution {
public:
	int findKthLargest(vector<int>& nums, int k) {
		sort(nums.begin(), nums.end());
		int count = 0;
		for (int i = nums.size() - 1; i >= 0; i--) {
			if (count == k - 1) {
				return nums[i];
			}
			count++;
		}
		return 0;
	}
};
//?????????
class Solution {
public:
	int finalPositionOfSnake(int n, vector<string>& commands) {
		vector<vector<int>> matrix;
		matrix.resize(n);
		for (int i = 0; i < n; i++) {
			matrix[i].resize(n);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				matrix[i][j] = (i * n) + j;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cout << matrix[i][j] << " ";
			}
			cout << endl;
		}
		int i = 0;
		int j = 0;
		for (int f = 0; f < commands.size(); f++) {
			if (commands[f].compare("RIGHT") == 0) {
				j++;

			}
			else if (commands[f].compare("DOWN") == 0) {
				i++;
			}
			else if (commands[f].compare("LEFT") == 0) {
				j--;

			}
			else if (commands[f].compare("UP") == 0) {
				i--;

			}
		}

		return matrix[i][j];
	}
};
//2942?????????????????????
class Solution {
public:
	vector<int> findWordsContaining(vector<string>& words, char x) {
		vector<int>  result;
		for (int i = 0; i < words.size(); i++) {
			for (int j = 0; j < words[i].size(); j++) {
				if (words[i][j] == x) {
					result.push_back(i);
					break;
				}
			}
		}
		return result;
	}
};
//2574.???????????
class Solution {
public:
	vector<int> leftRightDifference(vector<int>& nums) {
		vector<int> leftsum;
		vector<int> rightsum;
		leftsum.push_back(0);
		int sum = 0;
		for (int i = 1; i < nums.size(); i++) {
			sum += nums[i - 1];
			leftsum.push_back(sum);
		}
		reverse(nums.begin(), nums.end());
		rightsum.push_back(0);
		sum = 0;
		for (int i = 1; i < nums.size(); i++) {
			sum += nums[i - 1];
			rightsum.push_back(sum);
		}
		reverse(rightsum.begin(), rightsum.end());
		vector<int> result;
		for (int i = 0; i < nums.size(); i++) {
			int temp = abs(leftsum[i] - rightsum[i]);
			result.push_back(temp);
		}
		return result;
	}
};
//??????????????
class Solution {
public:
	int theMaximumAchievableX(int num, int t) {
		return (num + t) * 2 - num;
	}
};
//2798.???????????? ????????
class Solution {
public:
	int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) {
		int count = 0;
		for (int i = 0; i < hours.size(); i++) {
			if (hours[i] >= target) {
				count++;
			}
		}
		return count;
	}
};
//3423.?????????????????????
class Solution {
public:
	int maxAdjacentDistance(vector<int>& nums) {
		int max = 0;
		int flag = 1;
		for (int i = 1; i < nums.size(); i++) {
			if (flag == 1) {
				max = abs(nums[i] - nums[i - 1]);
				flag = 0;
			}
			else {
				if (abs(nums[i] - nums[i - 1]) > max) {
					max = abs(nums[i] - nums[i - 1]);
				}
			}
		}
		if (abs(nums[0] - nums[nums.size() - 1]) > max) {
			max = abs(nums[0] - nums[nums.size() - 1]);
		}
		return max;
	}
};
//?????????
class Solution {
public:
	int sumOfGoodNumbers(vector<int>& nums, int k) {
		int sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			int flag = 1;
			if ((i - k) >= 0 && nums[i - k] >= nums[i]) {
				flag = 0;
			}
			if ((i + k) < nums.size() && nums[i + k] >= nums[i]) {
				flag = 0;
			}
			if (flag == 1) {
				sum += nums[i];
			}
		}
		return sum;
	}
};
//????????????
class Solution {
	public int numberOfPairs(int[] nums1, int[] nums2, int k) {
		int count = 0;
		for (int i = 0; i < nums1.length; i++) {
			for (int j = 0; j < nums2.length; j++) {
				if (nums1[i] % (nums2[j] * k) == 0) {
					count++;
				}
			}
		}
		return count;
	}
}
//2824.??????????????????
class Solution {
public:
	int countPairs(vector<int>& nums, int target) {
		int count = 0;
		for (int i = 0; i < nums.size() - 1; i++) {
			for (int j = i + 1; j < nums.size(); j++) {
				if (nums[i] + nums[j] < target) {
					count++;
				}
			}
		}
		return count;
	}
};
//2643.????????
class Solution {
public:
	vector<int> rowAndMaximumOnes(vector<vector<int>>& mat) {
		int Max_ont_count = 0;
		int flag = 1;
		for (int i = 0; i < mat.size(); i++) {
			int count = 0;
			for (int j = 0; j < mat[i].size(); j++) {
				if (mat[i][j] == 1) {
					count++;
				}
			}
			if (flag == 1) {
				Max_ont_count = count;
				flag = 0;
			}
			else {
				if (count > Max_ont_count) {
					Max_ont_count = count;
				}
			}
		}
		vector<int> result;
		for (int i = 0; i < mat.size(); i++) {
			int count = 0;
			for (int j = 0; j < mat[i].size(); j++) {
				if (mat[i][j] == 1) {
					count++;
				}
			}
			if (count == Max_ont_count) {
				result.push_back(i);
				result.push_back(Max_ont_count);
				break;
			}
		}
		return result;
	}
};
//3264.K?????????????????I
class Solution {
public:
	vector<int> getFinalState(vector<int>& nums, int k, int multiplier) {
		while (k > 0) {
			vector<int> ::iterator min = min_element(nums.begin(), nums.end());
			int i;
			for (i = 0; i < nums.size(); i++) {
				if (nums[i] == (*min)) {
					break;
				}
			}
			nums[i] *= multiplier;
			k--;
		}
		return nums;
	}
};
//??????????
class Solution {
public:
	int numIdenticalPairs(vector<int>& nums) {
		int count = 0;
		for (int i = 0; i < nums.size() - 1; i++) {
			for (int j = i + 1; j < nums.size(); j++) {
				if (nums[i] == nums[j]) {
					count++;
				}
			}
		}
		return count;
	}
};
//1773.?????????????????????
class Solution {
public:
	string Matches_type[3] = { "type","color","name" };
	int countMatches(vector<vector<string>>& items, string ruleKey, string ruleValue) {
		int count = 0;
		for (int i = 0; i < items.size(); i++) {
			for (int j = 0; j < items[i].size(); j++) {
				if (items[i][j].compare(ruleValue) == 0 && Matches_type[j].compare(ruleKey) == 0) {
					count++;
				}
			}
		}
		return count;
	}
};
//3065.??????????????????|
class Solution {
public:
	int minOperations(vector<int>& nums, int k) {
		sort(nums.begin(), nums.end());
		int count = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] >= k) {
				break;
			}
			count++;
		}
		return count;
	}
};
//3467.?????????????
class Solution {
public:
	vector<int> transformArray(vector<int>& nums) {
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] % 2 == 0) {
				nums[i] = 0;
			}
			else {
				nums[i] = 1;
			}
		}
		sort(nums.begin(), nums.end());
		return nums;
	}
};
//
class Solution {
public:
	bool canAliceWin(vector<int>& nums) {
		int one_sum = 0;
		int second_sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] >= 0 && nums[i] <= 9) {
				one_sum += nums[i];
			}
			else {
				second_sum += nums[i];
			}
		}
		if (one_sum == second_sum) {
			return false;
		}
		else {
			return true;
		}
	}
};
//3233 ??????
class Solution {
public:
	bool canAliceWin(vector<int>& nums) {
		int one_sum = 0;
		int second_sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] >= 0 && nums[i] <= 9) {
				one_sum += nums[i];
			}
			else {
				second_sum += nums[i];
			}
		}
		if (one_sum == second_sum) {
			return false;
		}
		else {
			return true;
		}
	}
};
//2427.?????????
class Solution {
public:
	int commonFactors(int a, int b) {
		int count = 0;
		if (a >= b) {
			for (int i = 1; i <= b; i++) {
				if (a % i == 0 && b % i == 0) {
					count++;
				}
			}
		}
		else {
			for (int i = 1; i <= a; i++) {
				if (a % i == 0 && b % i == 0) {
					count++;
				}
			}
		}
		return count;
	}
};
//2810.???????
class Solution {
public:
	string finalString(string s) {
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'i') {
				reverse(s.begin(), s.begin() + i);
				s.erase(s.begin() + i);
				i--;
			}
		}
		return s;
	}
};
//????????????
class Solution {
public:
	int countKeyChanges(string s) {
		int count = 0;

		for (int i = 0; i < s.size(); i++) {
			if (s[i] >= 'A' && s[i] <= 'Z') {
				s[i] += 32;
			}
		}
		for (int i = 1; i < s.size(); i++) {
			if (s[i] - s[i - 1] != 0) {
				count++;

			}
		}
		return count;
	}
};
//?????????????????
class Solution {
public:
	string replaceDigits(string s) {
		for (int i = 1; i < s.size(); i += 2) {
			s[i] = s[i] - '0' + s[i - 1];
		}
		return s;
	}
};
//????????????I
class Solution {
public:
	vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
		vector<int> result;
		for (int i = 0; i < nums1.size(); i++) {
			int j = 0;
			int flag = 0;
			for (; j < nums2.size(); j++) {
				if (nums2[j] == nums1[i]) {
					flag = 1;
					break;
				}
			}
			if (flag == 1) {
				int f = j + 1;
				int flag1 = 0;
				for (; f < nums2.size(); f++) {
					if (nums2[f] > nums2[j]) {
						flag1 = 1;
						break;
					}
				}
				if (flag1 == 1) {
					result.push_back(nums2[f]);
				}
				else {
					result.push_back(-1);
				}
			}
			else {
				result.push_back(-1);
			}
		}
		return result;
	}
};
//?????????????
class Solution {
public:
	bool isAcronym(vector<string>& words, string s) {
		string result;
		for (int i = 0; i < words.size(); i++) {
			result += words[i][0];
		}
		if (result.compare(s) == 0) {
			return true;
		}
		else {
			return false;
		}
	}
};
//1431.??????????????
class Solution {
public:
	vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
		vector<bool> result;
		for (int i = 0; i < candies.size(); i++) {
			candies[i] += extraCandies;
			vector<int> ::iterator it = max_element(candies.begin(), candies.end());
			if (candies[i] == *it) {
				result.push_back(true);
			}
			else {
				result.push_back(false);
			}
			candies[i] -= extraCandies;
		}
		return result;
	}
};
//?????????????
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	int sum = 0;
	void Tree_Traversal(TreeNode* root, string& str) {
		if (root->right == NULL && root->left == NULL) {
			sum += stoi(str);
			return;
		}
		if (root->left != NULL) {
			str += root->left->val + '0';
			Tree_Traversal(root->left, str);
			str.pop_back();
		}
		if (root->right != NULL) {
			str += root->right->val + '0';
			Tree_Traversal(root->right, str);
			str.pop_back();
		}
	}
	int sumNumbers(TreeNode* root) {
		string str;
		if (root->left == NULL && root->right == NULL) {
			return root->val;
		}
		str.push_back(root->val + '0');
		Tree_Traversal(root, str);
		return sum;
	}
};
//2278.???????????????
class Solution {
public:
	int percentageLetter(string s, char letter) {
		int count = 0;
		for (int i = 0; i < s.size(); i++) {
			if (letter == s[i]) {
				count++;
			}
		}
		double rate = count * 1.0 / s.size();
		int r = (int)(rate * 100);
		return r;
	}
};
//2006.????????K?????????
class Solution {
public:
	int countKDifference(vector<int>& nums, int k) {
		int count = 0;
		for (int i = 0; i < nums.size() - 1; i++) {
			for (int j = i + 1; j < nums.size(); j++) {
				if (abs(nums[i] - nums[j]) == k) {
					count++;
				}
			}
		}
		return count;
	}
};
//???????
class Solution {
public:
	string dynamicPassword(string password, int target) {
		for (int i = 0; i < target; i++) {
			password += password[i];
		}
		int i = 0;
		while (i < target) {
			password.erase(password.begin());
			i++;
		}
		return password;
	}
};
//????????????class Solution {
public:
	int countTestedDevices(vector<int>& batteryPercentages) {
		int count = 0;
		for (int i = 0; i < batteryPercentages.size(); i++) {
			if (batteryPercentages[i] == 0) {
				continue;
			}
			else {
				count++;
			}
			for (int j = i + 1; j < batteryPercentages.size(); j++) {
				batteryPercentages[j] = max(0, batteryPercentages[j] - 1);
			}
		}
		return count;
	}
};
class Solution {
public:
	int countTestedDevices(vector<int>& batteryPercentages) {
		int count = 0;
		for (int i = 0; i < batteryPercentages.size(); i++) {
			if (batteryPercentages[i] == 0) {
				continue;
			}
			else {
				count++;
			}
			for (int j = i + 1; j < batteryPercentages.size(); j++) {
				batteryPercentages[j] = max(0, batteryPercentages[j] - 1);
			}
		}
		return count;
	}
};
//2011.????????
class Solution {
public:
	int finalValueAfterOperations(vector<string>& operations) {
		int count = 0;
		for (int i = 0; i < operations.size(); i++) {
			int flag = 1;
			for (int j = 0; j < operations[i].size(); j++) {
				if (operations[i][j] == '-') {
					flag = 0;
					break;
				}
			}
			if (flag == 0) {
				count--;
			}
			else {
				count++;
			}
		}
		return count;
	}
};
class Solution {
public:
	string defangIPaddr(string address) {
		string result;
		result.clear();
		for (int i = 0; i < address.size(); i++) {
			if (address[i] == '.') {
				result.push_back('[');
				result.push_back('.');
				result.push_back(']');
			}
			else {
				result.push_back(address[i]);
			}
		}
		return result;

	}
};
//1299.?????????????
class Solution {
public:
	vector<int> replaceElements(vector<int>& arr) {
		vector<int> result;
		for (int i = 0; i < arr.size(); i++) {
			vector<int> ::iterator it = max_element(arr.begin() + i + 1, arr.end());
			if (i == arr.size() - 1) {
				break;
			}
			else {
				result.push_back(*it);
			}
		}
		result.push_back(-1);
		return result;
	}
};
class Solution {
public:
	int returnToBoundaryCount(vector<int>& nums) {
		int count = 0;
		int count1 = 0;
		for (int i = 0; i < nums.size(); i++) {
			count += nums[i];
			if (count == 0) {
				count1++;
			}
		}
		return count1;
	}
};
//???λλ??С??
class Solution {
public:
	int smallestNumber(int n) {
		if (n == 1) {
			return 1;
		}
		while (n >= 3) {
			int flag = 0;
			vector<int> temp;
			temp.clear();
			int number = n;
			while (number) {
				temp.push_back(number % 2);
				number /= 2;
			}
			for (int i = 0; i < temp.size(); i++) {
				if (temp[i] == 0) {
					flag = 1;
					break;
				}
			}
			if (flag == 0) {
				return n;
			}
			n++;
		}
		return 0;
	}
};
//???????
class Solution {
public:
	int number[26] = { 26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1 };
	int reverseDegree(string s) {
		int sum = 0;
		for (int i = 0; i < s.size(); i++) {
			sum += (number[s[i] - 'a'] * (i + 1));
		}
		return sum;
	}
};
// 2595.??λ?
class Solution {
public:

	vector<int> evenOddBit(int n) {
		vector<int> bit;
		vector<int> result;
		result.resize(2);
		while (n) {
			bit.push_back(n % 2);
			n /= 2;
		}
		for (int i = 0; i < bit.size(); i++) {
			if (i % 2 == 0 && bit[i] == 1) {
				result[0]++;
			}
			else if (i % 2 != 0 && bit[i] == 1) {
				result[1]++;
			}
		}
		return result;
	}
};
//3285.??ψ????? 
class Solution {
public:
	vector<int> stableMountains(vector<int>& height, int threshold) {
		vector<int> result;
		for (int i = 1; i < height.size(); i++) {
			if (height[i - 1] > threshold) {
				result.push_back(i);
			}
		}
		return result;
	}
};
//LCR.?????
class Solution {
public:
	int calculate(string s) {
		int x = 1;
		int y = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'A') {
				x = 2 * x + y;
			}
			else if (s[i] == 'B') {
				y = 2 * y + x;
			}
		}
		return x + y;
	}
};
//3184.??????????I
class Solution {
public:
	int countCompleteDayPairs(vector<int>& hours) {
		int count = 0;
		for (int i = 0; i < hours.size() - 1; i++) {
			for (int j = i + 1; j < hours.size(); j++) {
				int temp = hours[i] + hours[j];
				if (temp % 24 == 0) {
					count++;
				}
			}
		}
		return count;
	}
};
//1662.??}????ˇ?Р?
class Solution {
public:
	bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {
		string w1, w2;
		for (int i = 0; i < word1.size(); i++) {
			w1 += word1[i];
		}
		for (int i = 0; i < word2.size(); i++) {
			w2 += word2[i];
		}
		if (w1.compare(w2) == 0) {
			return true;
		}
		else {
			return false;
		}
	}
};
//????????????λ
class Solution {
public:
	int countPrimeSetBits(int left, int right) {
		int count = 0;
		while (left <= right) {
			int number = left;
			int onecount = 0;
			while (number) {
				if (number & 1 == 1) {
					onecount++;
				}
				number = number >> 1;
			}
			int flag = 0;
			for (int i = 2; i < onecount; i++) {
				if (onecount % i == 0) {
					flag = 1;
					break;
				}
			}
			if (onecount != 1) {
				if (flag == 0) {
					count++;
					cout << left << endl;
				}
			}
			left++;
		}
		return count;
	}
};
//2733.??ˇ?С???ˇ???
class Solution {
public:
	int findNonMinOrMax(vector<int>& nums) {
		vector<int> ::iterator minit = min_element(nums.begin(), nums.end());
		vector<int> ::iterator maxit = max_element(nums.begin(), nums.end());

		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] > (*minit) && nums[i] < (*maxit)) {
				return nums[i];
			}
		}
		return -1;
	}
};
//1534.?????
class Solution {
public:
	int countGoodTriplets(vector<int>& arr, int a, int b, int c) {
		int count = 0;
		for (int i = 0; i < arr.size() - 2; i++) {
			for (int j = i + 1; j < arr.size() - 1; j++) {
				for (int k = j + 1; k < arr.size(); k++) {
					if (abs(arr[i] - arr[j]) <= a && abs(arr[j] - arr[k]) <= b && abs(arr[i] - arr[k]) <= c) {
						count++;
					}
				}
			}
		}
		return count;
	}
};
//1880.?????ˇ???????
class Solution {
public:
	bool isSumEqual(string firstWord, string secondWord, string targetWord) {
		string str1;
		for (int i = 0; i < firstWord.size(); i++) {
			str1.push_back(firstWord[i] - 'a' + '0');
		}
		string str2;
		for (int i = 0; i < secondWord.size(); i++) {
			str2.push_back(secondWord[i] - 'a' + '0');
		}
		string tar;
		for (int i = 0; i < targetWord.size(); i++) {
			tar.push_back(targetWord[i] - 'a' + '0');
		}
		int number1 = stoi(str1);
		int number2 = stoi(str2);
		int target = stoi(tar);
		if (number1 + number2 == target) {
			return true;
		}
		else {
			return false;
		}
		return true;
	}
};
//2206.??????Р???
class Solution {
public:
	bool divideArray(vector<int>& nums) {
		map<int, int> map_nums;
		for (int i = 0; i < nums.size(); i++) {
			map<int, int> ::iterator it = map_nums.find(nums[i]);
			if (it != map_nums.end()) {
				it->second += 1;
			}
			else {
				map_nums.insert(make_pair(nums[i], 1));
			}
		}
		for (map<int, int> ::iterator it = map_nums.begin(); it != map_nums.end(); it++) {
			if (it->second % 2 != 0) {
				return false;
			}
		}
		return true;
	}
};
//2815.?????????
class Solution {
public:
	int maxSum(vector<int>& nums) {
		int sum = 0;
		vector<int>  rseult;
		for (int i = 0; i < nums.size() - 1; i++) {
			for (int j = i + 1; j < nums.size(); j++) {
				int num1 = nums[i];
				int num2 = nums[j];
				int max1 = 0;
				int max2 = 0;
				while (num1) {
					if ((num1 % 10) > max1) {
						max1 = num1 % 10;
					}
					num1 /= 10;
				}
				while (num2) {
					if ((num2 % 10) > max2) {
						max2 = num2 % 10;
					}
					num2 /= 10;
				}
				if (max1 == max2) {
					rseult.push_back(nums[i] + nums[j]);
				}
			}
		}
		if (rseult.size() != 0) {
			vector<int> ::iterator it = max_element(rseult.begin(), rseult.end());
			return *it;
		}
		else
			return -1;
	}
};
//2.}?Р?
# Definition for singly - linked list.
# class ListNode :
	#     def __init__(self, val = 0, next = None) :
	#         self.val = val
	#         self.next = next
	class Solution :
	def addTwoNumbers(self, l1: Optional[ListNode], l2 : Optional[ListNode])->Optional[ListNode] :
	l1_str = ""
	l2_str = ""
	while l1 :
		l1_str = l1_str + str(l1.val)
		l1 = l1.next
		l1_str = l1_str[:: - 1]
		while l2 :
			l2_str = l2_str + str(l2.val)
			l2 = l2.next
			l2_str = l2_str[:: - 1]
			num = int(l1_str) + int(l2_str)
			num = str(num)
			num = num[:: - 1]
			head = None
			ptr = None
			for i in range(0, len(num)) :
				newnode = ListNode(int(num[i]), None)
				if head == None :
					head = newnode
					ptr = head
				else :
					ptr.next = newnode
					ptr = newnode
					return head

					//1252.?????????
					class Solution :
					def maximumValue(self, strs: List[str]) -> int :
					max_list = []
					for i in range(0, len(strs)) :
						if strs[i].isdigit() != True :
							max_list.append(len(strs[i]))
						else :
							max_list.append(int(strs[i]))
							return max(max_list)class Solution {
							public:
								int oddCells(int m, int n, vector<vector<int>>& indices) {
									vector<vector<int>> result;
									result.resize(m);
									for (int i = 0; i < m; i++) {
										result[i].resize(n);
									}
									for (int i = 0; i < indices.size(); i++) {
										int rows = indices[i][0];
										int cols = indices[i][1];
										for (int j = 0; j < n; j++) {
											result[rows][j] += 1;
										}
										for (int i = 0; i < m; i++) {
											result[i][cols] += 1;
										}
									}
									int count = 0;
									for (int i = 0; i < m; i++) {
										for (int j = 0; j < n; j++) {
											if (result[i][j] % 2 != 0) {
												count += 1;
											}
										}
									}
									return count;
								}
						};


class Solution {
public:
	vector<vector<int>> result;
	vector<int> array;
	void backtricking(vector<int>& candidates, int sum, int target, int startindex) {
		if (sum > target) {
			return;
		}
		if (sum == target) {
			result.push_back(array);
			return;
		}
		for (int i = startindex; i < candidates.size(); i++) {
			sum += candidates[i];
			array.push_back(candidates[i]);
			backtricking(candidates, sum, target, i);
			sum -= candidates[i];
			array.pop_back();
		}
	}
	vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
		int startindex = 0;
		int sum = 0;
		backtricking(candidates, sum, target, startindex);
		return result;
	}
};
//961//???2N???????????????n???
class Solution {
public:
	int repeatedNTimes(vector<int>& nums) {
		map<int, int> key_value;
		for (int i = 0; i < nums.size(); i++) {
			auto it = key_value.find(nums[i]);
			if (it == key_value.end()) {
				key_value.insert(make_pair(nums[i], 1));
			}
			else {
				it->second += 1;
				if (it->second == nums.size() / 2) {
					return it->first;
				}
			}
		}
		return  0;
	}
};
//3158.???Ж}????XOR?
class Solution {
public:
	int duplicateNumbersXOR(vector<int>& nums) {
		int two_number = 0;
		int falg = 0;
		map<int, int> key_value;
		for (int i = 0; i < nums.size(); i++) {
			auto it = key_value.find(nums[i]);
			if (it == key_value.end()) {
				key_value.insert(make_pair(nums[i], 1));
			}
			else {
				it->second += 1;
				if (falg == 0) {
					two_number = it->first;
					falg = 1;
				}
				else {
					two_number = two_number ^ it->first;
				}
			}
		}
		return two_number;
	}
};
//2485.??????
class Solution {
public:
	int pivotInteger(int n) {
		int leftsum = 0;
		int rightsum = 0;
		int i = 1;
		int sum = 0;
		while (i <= n) {
			sum += i;
			i++;
		}
		i = 1;
		while (i <= n) {
			leftsum += i;
			if (leftsum == sum - leftsum + i) {
				return i;
			}
			i++;
		}
		return -1;
	}
};
// 121.ò????????
class Solution {
public:
	int maxProfit(vector<int>& prices) {
		int inf = 1e9;
		int minprice = inf, maxProfit = 0;
		for (int price : prices) {
			maxProfit = max(maxProfit, price - minprice);
			minprice = min(price, minprice);
		}
		return maxProfit;
	}
};
//3536.}????????
class Solution {
public:
	int maxProduct(int n) {
		vector<int> array;
		while (n) {
			array.push_back(n % 10);
			n /= 10;
		}
		vector<int> mul_number;
		for (int i = 0; i < array.size() - 1; i++) {
			for (int j = i + 1; j < array.size(); j++) {
				mul_number.push_back(array[j] * array[i]);
			}
		}
		auto max_number = max_element(mul_number.begin(), mul_number.end());
		return *max_number;
	}
};
//2176.?????Р??????????
class Solution {
public:
	int countPairs(vector<int>& nums, int k) {
		int count = 0;
		for (int i = 0; i < nums.size() - 1; i++) {
			for (int j = i + 1; j < nums.size(); j++) {
				if (((i * j) % k == 0) && nums[i] == nums[j]) {
					count++;
				}
			}
		}
		return count;
	}
};
//400.?Nλ??
class Solution {
public:
	int findNthDigit(int n) {
		int digit = 1;
		long start = 1;
		long count = 9;
		while (n > count) { // 1.
			n -= count;
			start *= 10;
			digit += 1;
			count = digit * start * 9;
		}
		long num = start + (n - 1) / digit; // 2.
		return to_string(num)[(n - 1) % digit] - '0'; // 3.
	}
};
//724.???????
class Solution {
public:
	int pivotIndex(vector<int>& nums) {
		int sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			sum += nums[i];
		}
		int left_sum = 0;
		int i = 0;
		for (i = 0; i < nums.size(); i++) {
			if ((sum - left_sum - nums[i]) == left_sum) {
				return i;
			}
			else {
				left_sum += nums[i];
			}
		}
		return -1;
	}
};

//38.????
class Solution {
public:
	string countAndSay(int n) {
		string countAndSay = "1";
		if (n == 1) {
			return countAndSay;
		}
		int i = 1;
		while (i < n) {
			int count = 0;
			string temp;
			int flag = 0;
			char str;
			for (int j = 0; j < countAndSay.size(); j++) {
				if (flag == 0) {
					str = countAndSay.at(j);
					flag = 1;
					count = 1;
				}
				else {
					if (countAndSay[j] == str) {
						count++;
					}
					else {
						temp += to_string(count);
						temp += str;
						str = countAndSay.at(j);
						count = 1;
					}
				}
				if (j == countAndSay.size() - 1) {
					temp += to_string(count);
					temp += str;
				}
			}
			countAndSay.clear();
			countAndSay = temp;
			i++;
		}
		return countAndSay;
	}
};
//561.????
class Solution {
public:
	int arrayPairSum(vector<int>& nums) {
		sort(nums.begin(), nums.end());
		int sum = 0;
		for (int i = 0; i < nums.size(); i += 2) {
			sum += min(nums[i], nums[i + 1]);
		}
		return sum;
	}
};
//1848.???????С?k
class Solution {
public:
	int getMinDistance(vector<int>& nums, int target, int start) {
		vector<int> distance;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] == target) {
				distance.push_back(abs(i - start));
			}
		}
		auto it = min_element(distance.begin(), distance.end());
		return *it;
	}
};
//1304.??0?N?????
class Solution {
public:
	vector<int> sumZero(int n) {
		vector<int> result;
		if (n % 2 == 0) {
			for (int i = 0; i < n / 2; i++) {
				result.push_back(1 + i);
				result.push_back(-(1 + i));
			}
		}
		else {
			result.push_back(0);
			for (int i = 0; i < n / 2; i++) {
				result.push_back(1 + i);
				result.push_back(-(1 + i));
			}
		}
		return result;
	}
};
//1385.}???????k?
class Solution {
public:
	int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) {
		int count = 0;
		for (int i = 0; i < arr1.size(); i++) {
			int flag = 0;
			for (int j = 0; j < arr2.size(); j++) {
				if (abs(arr1[i] - arr2[j]) <= d) {
					flag = 1;
					break;
				}
			}
			if (flag == 0) {
				count++;
			}
		}
		return count;
	}
};
//1346.??????}??ˇ???
class Solution {
public:
	bool checkIfExist(vector<int>& arr) {
		for (int i = 0; i < arr.size() - 1; i++) {
			for (int j = i + 1; j < arr.size(); j++) {
				if (arr[i] == 2 * arr[j] || arr[j] == 2 * arr[i]) {

					return true;
				}
			}
		}
		return false;
	}
};
//2748.āv??????
class Solution {
public:
	int countBeautifulPairs(vector<int>& nums) {
		int count = 0;
		for (int i = 0; i < nums.size() - 1; i++) {
			for (int j = i + 1; j < nums.size(); j++) {
				string num1 = to_string(nums[i]);
				string num2 = to_string(nums[j]);
				int number1 = num1[0] - '0';
				int number2 = num2[num2.size() - 1] - '0';
				if (__gcd(number1, number2) == 1) {
					count++;
				}
			}
		}
		return count;
	}
};
//1624.}?Р???????????
class Solution {
public:
	int maxLengthBetweenEqualCharacters(string s) {
		vector<int> result;
		for (int i = 0; i < s.size() - 1; i++) {
			for (int j = i + 1; j < s.size(); j++) {
				if (s[i] == s[j]) {
					result.push_back(j - i - 1);
				}
			}
		}
		if (result.size() == 0) {
			return -1;
		}
		auto it = max_element(result.begin(), result.end());
		return *it;
	}
};
//506.Р???
class Solution {
public:
	vector<string> findRelativeRanks(vector<int>& score) {
		map<int, int> socre_map;
		for (int i = 0; i < score.size(); i++) {
			socre_map.insert(make_pair(score[i], i));
		}
		vector<string> result;
		result.resize(score.size());
		int count = score.size();
		for (auto it = socre_map.begin(); it != socre_map.end(); it++) {
			if (count > 3) {
				string temp = to_string(count);
				result[it->second] = temp;
			}
			else {
				if (count == 1) {
					result[it->second] = "Gold Medal";
				}
				else if (count == 2) {
					result[it->second] = "Silver Medal";
				}
				else if (count == 3) {
					result[it->second] = "Bronze Medal";
				}
			}
			count--;
		}
		return result;
	}
};
//д????????
class Solution {
public:
	vector<string> splitWordsBySeparator(vector<string>& words, char separator) {
		//??vector<string> ??
		vector<string> result;
		//?zwordsв
		for (int i = 0; i < words.size(); i++) {
			int f = 0;
			int j = 0;
			//?zв??????ì?????ì????
			string word = words[i];
			while (j < word.size()) {
				if (word[j] == separator) {
					string temp(word.begin() + f, word.begin() + j);
					//?????????,???
					if (temp.size() != 0) {
						result.push_back(temp);
					}
					f = j + 1;
				}
				j++;
			}
			string temp(word.begin() + f, word.begin() + j);
			if (temp.size() != 0) {
				result.push_back(temp);
			}
		}
		return result;
	}
};
//2164.????????? 
class Solution {
public:
	vector<int> sortEvenOdd(vector<int>& nums) {
		vector<int> odds;
		vector<int> evens;
		for (int i = 0; i < nums.size(); i++) {
			if (i % 2 == 0) {
				evens.push_back(nums[i]);
			}
			else {
				odds.push_back(nums[i]);
			}
		}
		sort(evens.begin(), evens.end());
		int f = 0;
		sort(odds.begin(), odds.end(), greater<int>());
		int j = 0;
		vector<int> result;
		for (int i = 0; i < nums.size(); i++) {
			if (i % 2 == 0) {
				result.push_back(evens[f]);
				f++;
			}
			else {
				result.push_back(odds[j]);
				j++;
			}
		}
		return result;
	}
};
//3079.????????
class Solution {
public:
	int sumOfEncryptedInt(vector<int>& nums) {
		int sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			int number = nums[i];
			int max = 0;
			int count = 0;
			int cor_number = 0;
			while (number) {
				if (max < (number % 10)) {
					max = number % 10;
				}
				count++;
				number /= 10;
			}
			for (int j = 0; j < count; j++) {
				cor_number += (max * pow(10, count - j - 1));
			}
			sum += cor_number;
		}
		return sum;
	}
};
//1882.????????
class Solution {
public:
	int arraySign(vector<int>& nums) {
		int count = 0;//???????
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] == 0) {
				return 0;
			}
			if (nums[i] < 0) {
				count++;
			}
		}
		if (count % 2 != 0) {
			return -1;
		}
		else {
			return 1;
		}
	}
};
//1979.??????????
class Solution {
public:
	int findGCD(vector<int>& nums) {
		auto min_number = min_element(nums.begin(), nums.end());
		auto max_number = max_element(nums.begin(), nums.end());
		return __gcd(*max_number, *min_number);
	}
};
//3550.?λ???????С??
class Solution {
public:
	int smallestIndex(vector<int>& nums) {
		for (int i = 0; i < nums.size(); i++) {
			int number = nums[i];
			int sum = 0;
			while (number) {
				sum += (number % 10);
				number /= 10;
			}
			if (sum == i) {
				return i;
			}
		}
		return -1;
	}
};
//2833.?k??????
class Solution {
public:
	int furthestDistanceFromOrigin(string moves) {
		int L_count = 0;
		int R_count = 0;
		for (int i = 0; i < moves.size(); i++) {
			if (moves[i] == 'L') {
				L_count++;
			}
			else if (moves[i] == 'R') {
				R_count++;
			}
		}
		int count = moves.size() - R_count - L_count;
		if (R_count > L_count) {
			R_count += count;
			return R_count - L_count;
		}
		else if (R_count < L_count) {
			L_count += count;
			return L_count - R_count;
		}
		else {
			return L_count + count - R_count;
		}
	}
};
//64.?С·??
class Solution {
public:
	int minPathSum(vector<vector<int>>& grid) {
		//???в??
		vector<vector<int>> path;
		//?????
		path.resize(grid.size());
		for (int i = 0; i < grid.size(); i++) {
			path[i].resize(grid[i].size());
		}
		path[0][0] = grid[0][0];
		//??￡???￡?????
		for (int j = 1; j < path[0].size(); j++) {
			path[0][j] = path[0][j - 1] + grid[0][j];
		}
		for (int i = 1; i < path.size(); i++) {
			path[i][0] = path[i - 1][0] + grid[i][0];
		}
		//????????????????,?????????ì????,????Сì????ì??ì???? 
		for (int i = 1; i < path.size(); i++) {
			for (int j = 1; j < path[i].size(); j++) {
				if (path[i - 1][j] < path[i][j - 1]) {
					path[i][j] = grid[i][j] + path[i - 1][j];
				}
				else {
					path[i][j] = grid[i][j] + path[i][j - 1];
				}
			}
		}
		return path[path.size() - 1][path[0].size() - 1];
	}
};
//120.??ю?С·??
class Solution {
public:
	int minimumTotal(vector<vector<int>>& triangle) {
		//??resultpath·????
		vector<vector<int>> resultpath;
		resultpath.resize(triangle.size());
		for (int i = 0; i < triangle.size(); i++) {
			resultpath[i].resize(triangle[i].size());
		}
		//???resultpath???????
		for (int j = 0; j < resultpath.size(); j++) {
			resultpath[resultpath.size() - 1][j] = triangle[triangle.size() - 1][j];
		}
		for (int i = resultpath.size() - 2; i >= 0; i--) {
			for (int j = 0; j < resultpath[i].size(); j++) {
				resultpath[i][j] = triangle[i][j] + min(resultpath[i + 1][j], resultpath[i + 1][j + 1]);
			}
		}
		return resultpath[0][0];
	}
};
//1791.??чэ???ф??
class Solution {
public:
	int findCenter(vector<vector<int>>& edges) {
		//??map??ì???????Ж???
		map<int, int> node;
		for (int i = 0; i < edges.size(); i++) {
			auto it = node.find(edges[i][0]);
			if (it != node.end()) {
				it->second += 1;
				//????????????2,??????
				if (it->second >= 2) {
					return it->first;
				}
			}
			else {
				node.insert(make_pair(edges[i][0], 1));
			}
			it = node.find(edges[i][1]);
			if (it != node.end()) {
				it->second += 1;
				//????????????2,??????
				if (it->second >= 2) {
					return it->first;
				}
			}
			else {
				node.insert(make_pair(edges[i][1], 1));
			}

		}
		return -1;
	}
};
//2042.????????ˇ???
class Solution {
public:
	bool areNumbersAscending(string s) {
		int i = 0;
		int j = 0;
		vector<int> result;
		while (j < s.size()) {
			if (s[j] >= '0' && s[j] <= '9') {
				i = j;
				while (s[j] >= '0' && s[j] <= '9') {
					j++;
				}
				string temp(s.begin() + i, s.begin() + j);
				int number = stoi(temp);
				cout << number << " ";
				result.push_back(number);
			}
			j++;
		}
		for (int i = 1; i < result.size(); i++) {
			if (result[i] <= result[i - 1]) {
				return false;
			}
		}
		return true;
	}
};
//1991.???????λ?
class Solution {
public:
	int findMiddleIndex(vector<int>& nums) {
		int sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			sum += nums[i];
		}
		int acc_number = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (sum - nums[i] - acc_number == acc_number) {
				return i;
			}
			acc_number += nums[i];
		}
		return -1;
	}
};
//884.?????????
class Solution {
public:
	bool backspaceCompare(string s, string t) {
		string s1;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '#' && s1.size() != 0) {
				s1.pop_back();
			}
			else if (s[i] == '#' && s1.size() == 0) {
				s1.clear();
			}
			else if (s[i] != '#') {
				s1.push_back(s[i]);
			}
		}
		string t1;
		for (int i = 0; i < t.size(); i++) {
			if (t[i] == '#' && t1.size() != 0) {
				t1.pop_back();
			}
			else if (t[i] == '#' && t1.size() == 0) {
				t1.clear();
			}
			else if (t[i] != '#') {
				t1.push_back(t[i]);
			}
		}
		cout << s1 << " " << t1 << endl;
		if (s1 == t1) {
			return true;
		}
		else {
			return false;
		}
	}
};
//1528.?т?????
class Solution {
public:
	string restoreString(string s, vector<int>& indices) {
		string result;
		result.resize(s.size());
		for (int i = 0; i < indices.size(); i++) {
			result[indices[i]] = s[i];
		}
		return result;
	}
};
//1375.?????????????
class Solution {
public:
	int numTimesAllBlue(vector<int>& flips) {
		/*string result;
		//?f??
		string temp;
		temp.resize(flips.size(),'0');
		result.resize(flips.size(),'0');
		int count  = 0;
		for(int i = 0;i < flips.size();i++){
			temp[i] = '1';
			result[flips[i] - 1] = '1';
			if(result == temp){
				count++;
			}
		}
		*/
		//????
		int count = 0;
		int maxval = flips[0];
		for (int i = 0; i < flips.size(); i++) {
			maxval = max(maxval, flips[i]);
			if (maxval == i + 1) {
				count++;
			}
		}
		return count;
	}
};
//2562.??????j?
class Solution {
public:
	long long findTheArrayConcVal(vector<int>& nums) {
		long long sum = 0;
		int left = 0;
		int right = nums.size() - 1;
		while (left <= right) {
			string number;
			if (left != right) {
				number = to_string(nums[left]) + to_string(nums[right]);
			}
			else {
				number = to_string(nums[left]);
			}
			int num = stoi(number);
			sum += num;
			left++;
			right--;
		}
		return sum;
	}
};
//L135.??
class Solution {
public:
	vector<int> countNumbers(int cnt) {
		int num = pow(10, cnt);
		vector<int> result;
		for (int i = 1; i < num; i++) {
			result.push_back(i);
		}
		return result;
	}
};
//2475.????????????
class Solution {
public:
	int unequalTriplets(vector<int>& nums) {
		int count = 0;
		for (int i = 0; i < nums.size() - 2; i++) {
			for (int j = i + 1; j < nums.size() - 1; j++) {
				for (int k = j + 1; k < nums.size(); k++) {
					if (nums[i] != nums[j] && nums[i] != nums[k] && nums[j] != nums[k]) {
						count++;
					}
				}
			}
		}
		return count;
	}
};
//1550.????l????
class Solution {
public:
	bool threeConsecutiveOdds(vector<int>& arr) {
		for (int i = 2; i < arr.size(); i++) {
			if (arr[i] % 2 != 0 && arr[i - 1] % 2 != 0 && arr[i - 2] % 2 != 0) {
				return true;
			}
		}
		return false;
	}
};
//2932.???????????
class Solution {
public:
	int maximumStrongPairXor(vector<int>& nums) {
		vector<int> result;
		for (int i = 0; i < nums.size(); i++) {
			for (int j = i; j < nums.size(); j++) {
				if (abs(nums[i] - nums[j]) <= min(nums[i], nums[j])) {
					result.push_back(nums[i] ^ nums[j]);
				}
			}
		}
		auto it = max_element(result.begin(), result.end());
		return *it;
	}
};
//3115.??????k
class Solution {
public:
	int arr[30] = { 2,3,5,7,11,
				13,17,19,23,
				29,31,37,41,
				43,47,53,59,
				61,67,71,73,
				79,83,89,97 };
	int maximumPrimeDifference(vector<int>& nums) {
		set<int> prime_number;
		for (int i = 0; i < 30; i++) {
			prime_number.insert(arr[i]);
		}
		bool f1 = false;
		bool f2 = false;
		int left = 0;
		int right = nums.size() - 1;
		while (left <= right) {
			auto it = prime_number.find(nums[left]);;

			if (it != prime_number.end()) {
				f1 = true;
			}
			it = prime_number.find(nums[right]);
			if (it != prime_number.end()) {
				f2 = true;
			}
			if (!f1)left++;
			if (!f2)right--;
			if (f1 && f2) return abs(left - right);

		}
		return 0;
	}
};
//3572.选择不同的x值三元组使y值最大
class Solution {
public:
	int maxSumDistinctTriplet(vector<int>& x, vector<int>& y) {
		//生成一个无规则索引容器.
		unordered_map<int, int> x_y_reflection;
		//得到元素长度
		int length = x.size();
		//把x与y对应长度的值用容器串起来,并且把相等的值对应y值相比较,以改变y值
		for (int i = 0; i < length; i++) {
			unordered_map<int, int> ::iterator it = x_y_reflection.find(x[i]);
			if (it != x_y_reflection.end()) {
				if (y[i] > it->second) {
					it->second = y[i];
				}
			}
			else {
				x_y_reflection.insert(make_pair(x[i], y[i]));
			}
		}
		if (x_y_reflection.size() < 3) {
			return -1;
		}
		else {
			//生成一个result容器
			vector<int> result;
			for (unordered_map<int, int> ::iterator it = x_y_reflection.begin(); it != x_y_reflection.end(); it++) {
				result.push_back(it->second);
			}
			//排序
			sort(result.begin(), result.end(), greater<int>());
			return result[0] + result[1] + result[2];
		}
	}
};
//3142.判断矩阵是否满足条件
class Solution {
public:
	bool satisfiesConditions(vector<vector<int>>& grid) {
		for (int i = 0; i < grid.size() - 1; i++) {
			for (int j = 0; j < grid[i].size() - 1; j++) {
				if (grid[i][j] != grid[i + 1][j] || grid[i][j] == grid[i][j + 1]) {
					return false;
				}
			}
		}
		for (int j = 0; j < grid[0].size() - 1; j++) {
			if (grid[0][j] == grid[0][j + 1]) {
				return false;
			}
		}
		for (int j = 0; j < grid[0].size() - 1; j++) {
			if (grid[grid.size() - 1][j] == grid[grid.size() - 1][j + 1]) {
				return false;
			}
		}
		for (int i = 0; i < grid.size() - 1; i++) {
			if (grid[i][0] != grid[i + 1][0]) {
				return false;
			}
		}
		for (int i = 0; i < grid.size() - 1; i++) {
			if (grid[i][grid[i].size() - 1] != grid[i + 1][grid[i].size() - 1]) {
				return false;
			}
		}
		return true;
	}
};
//2395. 和相等的子数组
class Solution {
public:
	bool findSubarrays(vector<int>& nums) {
		set<int> result;
		for (int i = 0; i < nums.size() - 1; i++) {
			set<int> ::iterator it = result.find(nums[i] + nums[i + 1]);
			if (it == result.end()) {
				result.insert(nums[i] + nums[i + 1]);
			}
			else {
				return true;
			}
		}
		return false;
	}
};
// 3309.连接二进制表示可形成的最大数值
class Solution {
public:
	//描写函数把二进制字符串转化为十进制数
	int to_number(string max_number) {
		int temp = 0;
		for (int i = 0; i < max_number.size(); i++) {
			if (max_number[i] == '1') {
				temp += pow(2, max_number.size() - i - 1);
			}
		}
		return temp;
	}
	int maxGoodNumber(vector<int>& nums) {
		string num1;
		string num2;
		string num3;
		//创建三个容器，把数组的三个数字都转化为二进制字符串
		while (nums[0]) {
			num1.push_back((nums[0] % 2) + '0');
			nums[0] /= 2;
		}
		while (nums[1]) {
			num2.push_back((nums[1] % 2) + '0');
			nums[1] /= 2;
		}
		while (nums[2]) {
			num3.push_back((nums[2] % 2) + '0');
			nums[2] /= 2;
		}
		reverse(num1.begin(), num1.end());
		reverse(num2.begin(), num2.end());
		reverse(num3.begin(), num3.end());
		string max_number;
		vector<int> result;
		//把三个二进制字符串进行排列组合,然后用函数转化为整数存入result容器中
		max_number = num1 + num2 + num3;
		result.push_back(to_number(max_number));
		max_number = num1 + num3 + num2;
		result.push_back(to_number(max_number));
		max_number = num2 + num1 + num3;
		result.push_back(to_number(max_number));
		max_number = num2 + num3 + num1;
		result.push_back(to_number(max_number));
		max_number = num3 + num2 + num1;
		result.push_back(to_number(max_number));
		max_number = num3 + num1 + num2;
		result.push_back(to_number(max_number));
		//求最大值
		vector<int> ::iterator it = max_element(result.begin(), result.end());
		return  *it;

	}
};
//2293.极大极小游戏
class Solution {
public:
	int minMaxGame(vector<int>& nums) {
		while (nums.size() != 1) {
			vector<int> temp;
			int i = 0;
			while (i < nums.size() / 2) {
				if (i % 2 == 0) {
					temp.push_back(min(nums[2 * i], nums[2 * i + 1]));
				}
				else {
					temp.push_back(max(nums[2 * i], nums[2 * i + 1]));
				}
				i++;
			}
			nums = temp;
		}
		return nums[0];
	}
};
//2150.找出数组中的所有孤独的数字
class Solution {
public:
	vector<int> findLonely(vector<int>& nums) {
		vector<int> result;
		map<int, int> number_appear;
		for (int i = 0; i < nums.size(); i++) {
			map<int, int> ::iterator it = number_appear.find(nums[i]);
			if (it != number_appear.end()) {
				it->second += 1;
			}
			else {
				number_appear.insert(make_pair(nums[i], 1));
			}
		}
		for (int i = 0; i < nums.size(); i++) {
			map<int, int> ::iterator it = number_appear.find(nums[i]);
			if (it->second == 1) {
				map<int, int> ::iterator left_it = number_appear.find(nums[i] - 1);
				map<int, int> ::iterator right_it = number_appear.find(nums[i] + 1);
				if (left_it == number_appear.end() && right_it == number_appear.end()) {
					result.push_back(nums[i]);
				}
			}
		}
		return result;
	}
};
//657.机器人能否返回原地
class Solution {
public:
	bool judgeCircle(string moves) {
		int x = 0;
		int y = 0;
		if (moves.size() % 2 != 0) return false;
		for (int i = 0; i < moves.size(); i++) {
			if (moves[i] == 'U') {
				y += 1;
			}
			else if (moves[i] == 'D') {
				y -= 1;
			}
			else if (moves[i] == 'L') {
				x -= 1;
			}
			else if (moves[i] == 'R') {
				x += 1;
			}
		}
		if (x == 0 && y == 0) {
			return true;
		}
		else {
			return false;
		}
	}
};
//LCR 095.最长公共字序列
class Solution {
public:
	int longestCommonSubsequence(string text1, string text2) {
		vector<vector<int>> result;
		result.resize(text1.size() + 1);
		for (int i = 0; i < result.size(); i++) {
			result[i].resize(text2.size() + 1);
		}
		for (int i = 0; i < result.size(); i++) {
			result[i][0] = 0;
		}
		for (int j = 0; j < result[0].size(); j++) {
			result[0][j] = 0;
		}
		for (int i = 0; i < text1.size(); i++) {
			for (int j = 0; j < text2.size(); j++) {
				if (text1[i] == text2[j]) {
					result[i + 1][j + 1] = result[i + 1 - 1][j + 1 - 1] + 1;
				}
				else {
					result[i + 1][j + 1] = max(result[i + 1][j + 1 - 1], result[i + 1 - 1][j + 1]);
				}
			}
		}
		for (int i = 0; i < result.size(); i++) {
			for (int j = 0; j < result[i].size(); j++) {
				cout << result[i][j] << " ";
			}
			cout << endl;
		}
		return result[text1.size()][text2.size()];
	}

};
//718.最长子数组
class Solution {
public:
	int findLength(vector<int>& nums1, vector<int>& nums2) {
		vector<vector<int>> result;
		result.resize(nums1.size() + 1);
		for (int i = 0; i < result.size(); i++) {
			result[i].resize(nums2.size() + 1);
		}
		for (int j = 0; j < result[0].size(); j++) {
			result[0][j] = 0;
		}
		int maxlength = 0;
		for (int i = 0; i < result.size(); i++) {
			result[i][0] = 0;
		}
		for (int i = 0; i < nums1.size(); i++) {
			for (int j = 0; j < nums2.size(); j++) {
				if (nums1[i] == nums2[j]) {
					result[i + 1][j + 1] = result[i + 1 - 1][j + 1 - 1] + 1;
					maxlength = max(maxlength, result[i + 1][j + 1]);
				}
				else {
					result[i + 1][j + 1] = 0;
				}
			}
		}

		return maxlength;
	}
};
//069.山顶数组的峰顶索引
class Solution {
public:
	int peakIndexInMountainArray(vector<int>& arr) {
		int max = arr[0];
		for (int i = 1; i < arr.size() - 1; i++) {
			if (arr[i] > max) {
				max = arr[i];
			}
		}
		for (int i = 0; i < arr.size(); i++) {
			if (max == arr[i]) {
				return i;
			}
		}
		return 0;
	}
};
//位一的个数
class Solution {
public:
	int hammingWeight(uint32_t n) {
		int count = 0;
		while (n != 0) {
			if (n & 1 == 1) {
				count++;
			}
			n = n >> 1;
		}
		return count;
	}
};
//元素和最小的山行三元组I
class Solution {
public:
	int minimumSum(vector<int>& nums) {
		vector<int> result;
		for (int i = 0; i < nums.size() - 2; i++) {
			for (int j = i + 1; j < nums.size() - 1; j++) {
				for (int k = j + 1; k < nums.size(); k++) {
					if (nums[i] < nums[j] && nums[k] < nums[j]) {
						result.push_back(nums[i] + nums[j] + nums[k]);
					}
				}
			}
		}
		if (result.size() == 0) {
			return -1;
		}
		vector<int> ::iterator it = min_element(result.begin(), result.end());
		return *it;
	}
};
//2341.数组能形成多少数对

class Solution {
public:
	vector<int> numberOfPairs(vector<int>& nums) {
		map<int, int> result;
		for (int i = 0; i < nums.size(); i++) {
			auto it = result.find(nums[i]);
			if (it != result.end()) {
				it->second += 1;
			}
			else {
				result.insert(make_pair(nums[i], 1));
			}
		}
		int count = 0;
		int surplus_count = 0;
		for (map<int, int> ::iterator it = result.begin(); it != result.end(); it++) {
			count += it->second / 2;
			surplus_count += it->second % 2;
		}
		vector<int> temp;
		temp.push_back(count);
		temp.push_back(surplus_count);
		return temp;
	}
};
//比特位计数
class Solution {
public:
	vector<int> countBits(int n) {
		vector<int> result;
		int i = 0;
		while (i <= n) {
			int count = 0;
			int number = i;
			while (number) {
				if (number & 1 == 1) {
					count++;
				}
				number >>= 1;
			}
			result.push_back(count);
			i++;
		}
		return result;
	}
};
//判断一个数的数字计数是否等于这个数字的值
class Solution {
public:
	bool digitCount(string num) {
		map<int, int> map_vec;
		for (int i = 0; i < num.size(); i++) {
			map<int, int> ::iterator it = map_vec.find(num[i] - '0');
			if (it != map_vec.end()) {
				it->second += 1;
			}
			else {
				map_vec.insert(make_pair(num[i] - '0', 1));
			}
		}
		for (int i = 0; i < num.size(); i++) {
			map<int, int> ::iterator it = map_vec.find(i);
			if (it != map_vec.end()) {
				if (it->second != (num[i] - '0')) {
					return false;
				}
			}
			else {
				if (num[i] != '0') {
					return false;
				}
			}
		}
		return true;
	}
};
//1704.判断字符串的两半是否相似
class Solution {
public:
	bool halvesAreAlike(string s) {
		int half_pre_count = 0;
		for (int i = 0; i < s.size() / 2; i++) {
			if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'
				|| s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U'
				) {
				half_pre_count++;
			}
		}
		int half_back_count = 0;
		for (int i = s.size() / 2; i < s.size(); i++) {
			if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'
				|| s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U'
				) {
				half_back_count++;
			}
		}
		if (half_pre_count == half_back_count) {
			return true;
		}
		else {
			return false;
		}
	}
};
//1768.交替合并字符串
class Solution {
public:
	string mergeAlternately(string word1, string word2) {
		string result;
		int i = 0;
		int word1_j = 0;
		int word2_f = 0;
		for (int i = 0; i < min(word1.size(), word2.size()) * 2; i++) {
			if (i % 2 == 0) {
				result.push_back(word1[word1_j]);
				word1_j++;
			}
			else {
				result.push_back(word2[word2_f]);
				word2_f++;
			}
		}
		if (word1_j < word1.size()) {
			for (; word1_j < word1.size(); word1_j++) {
				result.push_back(word1[word1_j]);
			}
		}
		if (word2_f < word2.size()) {
			for (; word2_f < word2.size(); word2_f++) {
				result.push_back(word2[word2_f]);
			}
		}
		return result;
	}
};
//2129.将标题首字母大写
class Solution {
public:
	string capitalizeTitle(string title) {
		vector<string> result;
		if (title.size() == 1 || title.size() == 2) {
			for (int i = 0; i < title.size(); i++) {
				if (title[i] >= 'A' && title[i] <= 'Z') {
					title[i] += 32;
				}
			}
			cout << title << endl;
			return title;
		}
		int j = 0;
		int i = 0;
		for (int i = 1; i < title.size(); i++) {
			if (title[i - 1] == ' ') {
				string temp(title.begin() + j, title.begin() + i - 1);
				j = i;
				result.push_back(temp);
			}
			if (i == title.size() - 1) {
				string temp(title.begin() + j, title.end());
				j = i;
				result.push_back(temp);
			}
		}
		string final_result = "";
		for (int i = 0; i < result.size(); i++) {
			if (result[i].size() == 1 || result[i].size() == 2) {
				for (int j = 0; j < result[i].size(); j++) {
					if (result[i][j] >= 'A' && result[i][j] <= 'Z') {
						result[i][j] += 32;
					}
				}
				final_result += result[i] + " ";
			}
			else {
				if (result[i][0] >= 'a' && result[i][0] <= 'z') {
					result[i][0] -= 32;
				}
				for (int j = 1; j < result[i].size(); j++) {
					if (result[i][j] >= 'A' && result[i][j] <= 'Z') {
						result[i][j] += 32;
					}
				}
				final_result += result[i] + " ";
			}
		}
		final_result.pop_back();
		return final_result;
	}
};
//1995.统计特殊四元祖
class Solution {
public:
	int countQuadruplets(vector<int>& nums) {
		int count = 0;
		for (int i = 0; i < nums.size() - 3; i++) {
			for (int j = i + 1; j < nums.size() - 2; j++) {
				for (int k = j + 1; k < nums.size() - 1; k++) {
					for (int f = k + 1; f < nums.size(); f++) {
						if (nums[i] + nums[j] + nums[k] == nums[f]) {
							count++;
						}
					}
				}
			}
		}
		return count;
	}
};
//1816.截断句子
class Solution {
public:
	string truncateSentence(string s, int k) {
		vector<string> result;
		int i = 0;
		int j = 0;
		string word = "";
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == ' ') {
				string temp(s.begin() + i, s.begin() + j);
				result.push_back(temp);
				i = j + 1;
			}
			if (j == s.size() - 1) {
				string temp(s.begin() + i, s.end());
				result.push_back(temp);
			}
		}
		for (i = 0; i < result.size(); i++) {
			if (i < k - 1) {
				word += result[i] + " ";
			}
			else {
				word += result[i];
				break;
			}
		}
		return word;
	}
};
2586.统计字符串的元音字符数
class Solution {
public:
	int vowelStrings(vector<string>& words, int left, int right) {
		int count = 0;
		for (; left <= right; left++) {
			string temp = words[left];
			int flag1 = 0;
			int flag2 = 0;
			if (temp[0] == 'a' || temp[0] == 'e' || temp[0] == 'i' || temp[0] == 'o' || temp[0] == 'u') {
				flag1 = 0;
			}
			else {
				flag1 = 1;
			}
			if (temp[temp.size() - 1] == 'a' || temp[temp.size() - 1] == 'e' || temp[temp.size() - 1] == 'i' || temp[temp.size() - 1] == 'o' || temp[temp.size() - 1] == 'u') {
				flag2 = 0;
			}
			else {
				flag2 = 1;
			}
			if (flag1 == 0 && flag2 == 0) {
				count++;
			}
		}
		return count;
	}
};
//1732.找到最高海拔
class Solution {
public:
	int largestAltitude(vector<int>& gain) {
		vector<int> result;
		result.resize(gain.size() + 1, 0);
		result[0] = 0;
		result[1] = gain[0];
		int sum = 0;
		int j = 2;
		if (gain.size() < 2) {
			if (gain[0] < 0) {
				return 0;
			}
			else {
				return gain[0];
			}
		}
		sum = gain[0] + gain[1];
		for (int i = 2; i < gain.size(); i++) {
			result[j] = sum;
			j++;
			sum += gain[i];
		}
		result[j] = sum;
		vector<int> ::iterator maxit = max_element(result.begin(), result.end());
		return *maxit;
	}
};
3345.最小可整除数位乘积I
class Solution {
public:
	int smallestNumber(int n, int t) {
		int number = n;
		while (number <= 100) {
			int mul = 1;
			int temp = number;
			while (temp) {
				mul *= (temp % 10);
				temp /= 10;
			}
			if (mul % t == 0) {
				return number;
			}
			number++;
		}
		return 0;
	}
};
1025.除数博弈
class Solution {
public:
	bool divisorGame(int n) {
		if (n % 2 == 0) {
			return true;
		}
		else {
			return false;
		}
	}
};
//字符串中的第二大数字
class Solution {
public:
	int secondHighest(string s) {
		set<int> num;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] >= '0' && s[i] <= '9') {
				int temp = s[i] - '0';
				num.insert(temp);
			}
		}
		if (num.size() == 1 || num.size() == 0) {
			return -1;
		}
		else {
			int k = 0;
			for (set<int> ::iterator it = num.begin(); it != num.end(); it++) {
				if (k == num.size() - 2) {
					cout << *it << endl;
					return *it;
				}
				k++;
			}
			return 0;
		}
	}
};
//1619.删除某些元素后的数组均值
class Solution {
public:
	double trimMean(vector<int>& arr) {
		sort(arr.begin(), arr.end());
		int i = arr.size() / 20;
		int sum = 0;
		for (int j = i; j < arr.size() - i; j++) {
			sum += arr[j];
		}
		return sum * 1.0 / (arr.size() - i * 2);
	}
};
2966.划分数组并满足最大差限制
class Solution {
public:
	vector<vector<int>> divideArray(vector<int>& nums, int k) {
		vector<vector<int>> result;
		sort(nums.begin(), nums.end());
		for (int j = 0; j < nums.size(); j += 3) {
			if ((nums[j + 2] - nums[j]) > k) {
				result.clear();
				return result;
			}
			else {
				vector<int> temp;
				temp.push_back(nums[j]);
				temp.push_back(nums[j + 1]);
				temp.push_back(nums[j + 2]);
				result.push_back(temp);
			}
		}
		return result;
	}
};
//3442.奇偶频次间的最大差值
class Solution {
public:
	int maxDifference(string s) {
		map<char, int> str;
		for (int i = 0; i < s.size(); i++) {
			auto it = str.find(s[i]);
			if (it != str.end()) {
				it->second += 1;
			}
			else {
				str.insert(make_pair(s[i], 1));
			}
		}
		int max = 0;
		int min = 101;
		for (auto it = str.begin(); it != str.end(); it++) {
			if (it->second % 2 != 0) {
				if (it->second > max) {
					max = it->second;
				}
			}
			else {
				if (it->second < min) {
					min = it->second;
				}
			}
		}
		return max - min;
	}
};
//判定是否互为重拍字符串
class Solution {
public:
	bool CheckPermutation(string s1, string s2) {
		if (s1.size() != s2.size()) {
			return false;
		}
		sort(s1.begin(), s1.end());
		sort(s2.begin(), s2.end());
		for (int i = 0; i < s1.size(); i++) {
			if (s1[i] != s2[i]) {
				return false;
			}
		}
		return true;
	}
};
//最长公共子序列
class Solution {
public:
	int longestCommonSubsequence(string text1, string text2) {
		vector<vector<int>> result;
		result.resize(text1.size() + 1);
		for (int i = 0; i < result.size(); i++) {
			result[i].resize(text2.size() + 1);
		}
		for (int i = 0; i < result.size(); i++) {
			result[i][0] = 0;
		}
		for (int j = 0; j < result[0].size(); j++) {
			result[0][j] = 0;
		}
		for (int i = 0; i < text1.size(); i++) {
			for (int j = 0; j < text2.size(); j++) {
				if (text1[i] == text2[j]) {
					result[i + 1][j + 1] = result[i + 1 - 1][j + 1 - 1] + 1;
				}
				else {
					result[i + 1][j + 1] = max(result[i + 1][j + 1 - 1], result[i + 1 - 1][j + 1]);
				}
			}
		}
		return result[text1.size()][text2.size()];
	}
};
//2245.可被三整除的偶数的平均值
class Solution {
public:
	int averageValue(vector<int>& nums) {
		int sum = 0;
		int count = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] % 3 == 0 && nums[i] % 2 == 0) {
				sum += nums[i];
				count++;
			}
		}
		if (count == 0) {
			return 0;
		}
		else {
			return sum / count;
		}
	}
};
//1784.检查二进制字符串段
class Solution {
public:
	bool checkOnesSegment(string s) {
		int count = 0;
		int i = 0;
		while (i < s.size()) {
			if (i < s.size() && s[i] == '1') {
				count++;
				while (i < s.size() && s[i] != '0') {
					i++;
				}
			}
			if (i >= s.size()) {
				break;
			}
			i++;
		}
		if (count == 0 || count == 1) {
			return true;
		}
		else {
			return false;
		}
	}
};
1925.统计平方和的三元组数目
class Solution {
public:
	int countTriples(int n) {
		int count = 0;
		for (int a = 1; a <= n - 2; a++) {
			for (int b = a + 1; b <= n - 1; b++) {
				for (int c = b + 1; c <= n; c++) {
					if (pow(a, 2) + pow(b, 2) == pow(c, 2)) {
						count += 2;
					}
				}
			}
		}
		return count;
	}
};
//3622.判断整除性
class Solution {
public:
	bool checkDivisibility(int n) {
		int sum = 0;
		int mul = 1;
		int num = n;
		while (num) {
			sum += (num % 10);
			mul *= (num % 10);
			num /= 10;
		}
		if (n % (mul + sum) == 0) {
			return true;
		}
		else {
			return false;
		}
	}
};
//寻找比目标字母大的最小字母
class Solution {
public:
	char nextGreatestLetter(vector<char>& letters, char target) {
		for (int i = 0; i < letters.size(); i++) {
			if (letters[i] > target) {
				return letters[i];
			}
		}
		return letters[0];
	}
};
//数据流中的移动平均值
class MovingAverage {
public:
	/** Initialize your data structure here. */
	vector<int> num;
	int size;
	int sum;
	MovingAverage(int size) {
		this->size = size;
		sum = 0;
	}

	double next(int val) {
		num.push_back(val);
		sum += val;
		if (num.size() > this->size) {
			sum -= num[0];
			num.erase(num.begin());
			return sum * 1.0 / this->size;
		}
		else {
			return sum * 1.0 / num.size();
		}
	}
};

/**
 * Your MovingAverage object will be instantiated and called as such:
 * MovingAverage* obj = new MovingAverage(size);
 * double param_1 = obj->next(val);
 */
 //将偶数按照奇偶数转化
class Solution {
public:
	vector<int> transformArray(vector<int>& nums) {
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] % 2 == 0) {
				nums[i] = 0;
			}
			else {
				nums[i] = 1;
			}
		}
		sort(nums.begin(), nums.end());
		return nums;
	}
};
//寻找二叉搜索树的目标节点
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
	vector<int> array;
	void middle_travel(TreeNode* root) {
		if (root == NULL) {
			return;
		}
		middle_travel(root->left);
		array.push_back(root->val);
		middle_travel(root->right);
	}
	int findTargetNode(TreeNode* root, int cnt) {
		middle_travel(root);
		for (int i = array.size() - 1; i >= 0; i--) {
			cnt--;
			if (cnt == 0) {
				return array[i];
			}
		}
		return 0;
	}
};
//3641.判断操作后字符串中的数字是否相等I
class Solution {
public:
	bool hasSameDigits(string s) {
		while (s.size() != 2) {
			string num = "";
			for (int i = 0; i < s.size() - 1; i++) {
				num += to_string(((s[i] - '0') + (s[i + 1] - '0')) % 10);
			}
			s = num;
		}
		if (s[0] == s[1]) {
			return true;
		}
		else {
			return false;
		}

	}
};
//检查是否所有字符出现次数相同
class Solution {
public:
	bool areOccurrencesEqual(string s) {
		map<char, int> s_str;
		for (int i = 0; i < s.size(); i++) {
			map<char, int> ::iterator it = s_str.find(s[i]);
			if (it != s_str.end()) {
				it->second += 1;
			}
			else {
				s_str.insert(make_pair(s[i], 1));
			}
		}
		vector<int> result;
		for (auto it = s_str.begin(); it != s_str.end(); it++) {
			result.push_back(it->second);
		}
		int answer = result[0];
		for (int i = 0; i < result.size(); i++) {
			if (answer != result[i]) {
				return false;
			}
		}
		return true;
	}
};
//3274.检查棋盘颜色方格颜色是否相同
class Solution {
public:
	bool checkTwoChessboards(string coordinate1, string coordinate2) {
		int c1_color = 0;
		int c2_color = 0;
		if ((coordinate1[0] - 'a') % 2 == 0) {
			if ((coordinate1[1] - '1') % 2 == 0) {
				c1_color = 1;
			}
			else {
				c1_color = 0;
			}
		}
		else {
			if ((coordinate1[1] - '1') % 2 == 0) {
				c1_color = 0;
			}
			else {
				c1_color = 1;
			}
		}
		if ((coordinate2[0] - 'a') % 2 == 0) {
			if ((coordinate2[1] - '1') % 2 == 0) {
				c2_color = 1;
			}
			else {
				c2_color = 0;
			}
		}
		else {
			if ((coordinate2[1] - '1') % 2 == 0) {
				c2_color = 0;
			}
			else {
				c2_color = 1;
			}
		}
		if (c1_color == c2_color) {
			return true;
		}
		else {
			return false;
		}
	}
};
//1800.最大升序子数组之和
class Solution {
public:
	int maxAscendingSum(vector<int>& nums) {
		int i = 0;
		int maxsum = 0;
		vector<int> stack_num;
		int sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (stack_num.size() == 0) {
				sum += nums[i];
				stack_num.push_back(nums[i]);
			}
			else {
				if (nums[i] <= stack_num[stack_num.size() - 1]) {
					stack_num.clear();
					i--;
					if (sum > maxsum) {
						maxsum = sum;
					}
					sum = 0;
					continue;
				}
				else {
					stack_num.push_back(nums[i]);
					sum += nums[i];
				}
			}
		}
		if (sum > maxsum) {
			maxsum = sum;
		}
		return maxsum;
	}
};
//完成一个任务的最早时间
class Solution {
public:
	int earliestTime(vector<vector<int>>& tasks) {
		int mintime = 301;
		for (int i = 0; i < tasks.size(); i++) {
			if (mintime > (tasks[i][0] + tasks[i][1])) {
				mintime = tasks[i][0] + tasks[i][1];
			}
		}
		return mintime;
	}
};
//868.二进制间距
class Solution {
public:
	int binaryGap(int n) {
		vector<int> bit;
		while (n) {
			bit.push_back(n % 2);
			n /= 2;
		}
		vector<int> distance;
		int index = -1;
		for (int i = 0; i < bit.size(); i++) {
			if (bit[i] == 1) {
				if (index == -1) {
					index = i;
				}
				else {
					distance.push_back(i - index);
					index = i;
				}
			}
		}
		if (distance.size() == 0) {
			return 0;
		}
		else {
			vector<int> ::iterator maxit = max_element(distance.begin(), distance.end());
			return *maxit;
		}
	}
};
//1413.逐步求和得到正数的最小值
class Solution {
public:
	int minStartValue(vector<int>& nums) {
		int i = 1;
		while (1) {
			int flag = 0;
			int sum = i;
			for (int j = 0; j < nums.size(); j++) {
				sum += nums[j];
				if (sum < 1) {
					flag = 1;
					break;
				}
			}
			if (flag == 0) {
				break;
			}
			i++;
		}
		return i;
	}
};
//3427.变长子数组之和
class Solution {
public:
	int subarraySum(vector<int>& nums) {
		int i = 0;
		vector<int> sum_result;
		int total_sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			int index = max(0, i - nums[i]);
			int sum = 0;
			for (; index <= i; index++) {
				sum += nums[index];
			}
			total_sum += sum;
		}
		return total_sum;
	}
};
//魔术索引
class Solution {
public:
	int findMagicIndex(vector<int>& nums) {
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] == i) {
				return i;
			}
		}
		return -1;
	}
};
//2215.找出两数组的不同
class Solution {
public:
	vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {
		set<int> nums;
		for (int i = 0; i < nums1.size(); i++) {
			nums.insert(nums1[i]);
		}
		set<int> same_arr;
		for (int i = 0; i < nums2.size(); i++) {
			auto it = nums.find(nums2[i]);
			if (it != nums.end()) {
				same_arr.insert(nums2[i]);
			}
		}
		vector<int> new_nums1;
		for (int i = 0; i < nums1.size(); i++) {
			auto it = same_arr.find(nums1[i]);
			if (it == same_arr.end()) {
				new_nums1.push_back(nums1[i]);
			}
		}
		vector<int> new_nums2;
		for (int i = 0; i < nums2.size(); i++) {
			auto it = same_arr.find(nums2[i]);
			if (it == same_arr.end()) {
				new_nums2.push_back(nums2[i]);
			}
		}
		vector<vector<int>> result;
		set<int> s1(new_nums1.begin(), new_nums1.end());
		set<int> s2(new_nums2.begin(), new_nums2.end());
		new_nums1.assign(s1.begin(), s1.end());
		new_nums2.assign(s2.begin(), s2.end());
		result.push_back(new_nums1);
		result.push_back(new_nums2);
		return result;
	}
};
//3074.h重新分装苹果
class Solution {
public:
	int minimumBoxes(vector<int>& apple, vector<int>& capacity) {
		sort(capacity.begin(), capacity.end(), greater<int>());
		int sum = 0;
		for (int i = 0; i < apple.size(); i++) {
			sum += apple[i];
		}
		int count = 0;
		int new_sum = 0;
		for (int i = 0; i < capacity.size(); i++) {
			new_sum += capacity[i];
			if (new_sum >= sum) {
				count++;
				break;
			}
			else {
				count++;
			}
		}
		return count;
	}
};
//找出不同元素组数目差
class Solution {
public:
	vector<int> distinctDifferenceArray(vector<int>& nums) {
		vector<int> result;
		for (int i = 0; i < nums.size(); i++) {
			set<int> next_nums;
			set<int> back_nums;
			int j = 0;
			for (; j <= i; j++) {
				next_nums.insert(nums[j]);
			}
			for (; j < nums.size(); j++) {
				back_nums.insert(nums[j]);
			}
			result.push_back(next_nums.size() - back_nums.size());
		}
		return result;
	}
};
//是否所有1都相隔一个元素
class Solution {
public:
	bool kLengthApart(vector<int>& nums, int k) {
		int i = -1;
		int j = 0;
		for (; j < nums.size(); j++) {
			if (nums[j] == 1) {
				if (i == -1) {
					i = j;
				}
				else {
					if (j - i - 1 >= k) {
						i = j;
					}
					else {
						return false;
					}
				}
			}
		}
		return true;
	}
};

//2441.与对应负数同时存在的最大整数
class Solution {
public:
	int findMaxK(vector<int>& nums) {
		set<int> numbers;
		for (int i = 0; i < nums.size(); i++) {
			numbers.insert(nums[i]);
		}
		int k = -1;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] < 0) {
				int number = -1 * nums[i];
				auto it = numbers.find(number);
				if (it != numbers.end()) {
					if (number > k) {
						k = number;
					}
				}
			}
		}
		return k;
	}
};
//3658.奇数和和偶数和的最大公约数
class Solution {
public:
	int gcdOfOddEvenSums(int n) {
		int sumodd = 0;
		int i = 1;
		while (i <= n) {
			sumodd += (2 * i - 1);
			i++;
		}
		int sumeven = 0;
		i = 1;
		while (i <= n) {
			sumeven += (2 * i);
			i++;
		}
		int number = __gcd(sumodd, sumeven);
		return number;
	}
};
//3688.偶数的按位或运算
class Solution {
public:
	int evenNumberBitwiseORs(vector<int>& nums) {
		int num = -1;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] % 2 == 0) {
				if (num == -1) {
					num = nums[i];
				}
				else {
					num |= nums[i];
				}
			}
		}
		if (num == -1) {
			return 0;
		}
		else {
			return num;
		}
	}
};
//1399.统计最大组的数目
class Solution {
public:
	int countLargestGroup(int n) {
		vector<int> bit_sum;
		int i = 1;
		bit_sum.resize(37, 0);
		while (i <= n) {
			int number = i;
			int sum = 0;
			while (number) {
				sum += (number % 10);
				number /= 10;
			}
			bit_sum[sum] = bit_sum[sum] + 1;
			i++;
		}
		int max = -1;
		for (int i = 0; i < bit_sum.size(); i++) {
			if (bit_sum[i] > max) {
				max = bit_sum[i];
			}
		}
		int  count = 0;
		for (int i = 0; i < bit_sum.size(); i++) {
			if (bit_sum[i] == max) {
				count++;
			}
		}
		return count;
	}
};
//1313.解压缩编码列表
class Solution {
public:
	vector<int> decompressRLElist(vector<int>& nums) {
		vector<int> result;
		for (int i = 0; i < nums.size(); i += 2) {
			int count = nums[i];
			int j = 0;
			while (j < count) {
				result.push_back(nums[i + 1]);
				j++;
			}
		}
		return result;
	}
};
//1200 最小绝对差
class Solution {
public:
	vector<vector<int>> minimumAbsDifference(vector<int>& arr) {
		sort(arr.begin(), arr.end());
		int min = (int)(pow(10, 6) + 1);
		for (int i = 0; i < arr.size() - 1; i++) {
			if (min > abs(arr[i] - arr[i + 1])) {
				min = abs(arr[i] - arr[i + 1]);
			}
		}
		vector<vector<int>> result;
		for (int i = 0; i < arr.size() - 1; i++) {
			if (min == abs(arr[i] - arr[i + 1])) {
				vector<int> array;
				array.push_back(arr[i]);
				array.push_back(arr[i + 1]);
				result.push_back(array);
			}
		}
		return result;
	}
};
//1539.第k个缺失的正整数
class Solution {
public:
	int findKthPositive(vector<int>& arr, int k) {
		set<int> arrays;
		for (int i = 0; i < arr.size(); i++) {
			arrays.insert(arr[i]);
		}
		int count = 0;
		int i = 1;
		while (i <= 10000) {
			auto it = arrays.find(i);
			if (it == arrays.end()) {
				count++;
			}
			if (count >= k) {
				break;
			}
			i++;
		}
		return i;
	}
};
//1356根据数字二进制下1的数目排序
class Solution {
public:
	vector<int> sortByBits(vector<int>& arr) {
		sort(arr.begin(), arr.end());
		multimap<int, int> array;
		for (int i = 0; i < arr.size(); i++) {
			int number = arr[i];
			int count = 0;
			while (number) {
				if (1 == (number % 2)) {
					count++;
				}
				number >>= 1;
			}
			array.insert(make_pair(count, arr[i]));
		}
		vector<int> result;
		for (auto it = array.begin(); it != array.end(); it++) {
			result.push_back(it->second);
		}
		return result;

	}
};
//1827.最少操作使数组递增
class Solution {
public:
	int minOperations(vector<int>& nums) {
		int count = 0;
		for (int i = 1; i < nums.size(); i++) {
			while (nums[i] <= nums[i - 1]) {
				count++;
				nums[i] += 1;
			}
		}
		return count;
	}
};
//3663.出现频率最低的数字
class Solution {
public:
	int getLeastFrequentDigit(int n) {
		map<int, int> number_bit;
		while (n) {
			auto it = number_bit.find(n % 10);
			if (it != number_bit.end()) {
				it->second = it->second + 1;
			}
			else {
				number_bit.insert(make_pair(n % 10, 1));
			}
			n /= 10;
		}
		vector<int> result;
		result.resize(10, 12);
		for (auto it = number_bit.begin(); it != number_bit.end(); it++) {
			result[it->first] = it->second;
		}
		auto minit = min_element(result.begin(), result.end());
		for (int i = 0; i < result.size(); i++) {
			if (result[i] == *minit) {
				return i;
			}
		}
		return 0;
	}
};
class Solution {
public:
	int theMaximumAchievableX(int num, int t) {
		return (num + t) * 2 - num;
	}
};
//1684.统计一致字符串的数量。
class Solution {
public:
	int countConsistentStrings(string allowed, vector<string>& words) {
		set<char> str_detect;
		for (int i = 0; i < allowed.size(); i++) {
			str_detect.insert(allowed[i]);
		}
		int count = 0;
		for (int i = 0; i < words.size(); i++) {
			int flag = 0;
			for (int j = 0; j < words[i].size(); j++) {
				set<char> ::iterator  it = str_detect.find(words[i][j]);
				if (it == str_detect.end()) {
					flag = 1;
					break;
				}
			}
			if (flag == 0) {
				count++;
			}
		}
		return count;
	}
};
//3226.使两个整数相等的位更改次数
class Solution {
public:
	int minChanges(int n, int k) {
		vector<int> n_bit;
		n_bit.resize(64, 0);
		int i = 0;
		vector<int> k_bit;
		k_bit.resize(64, 0);
		int j = 0;
		while (n) {
			n_bit[i] = n % 2;
			n /= 2;
			i++;
		}
		while (k) {
			k_bit[j] = k % 2;
			k /= 2;
			j++;
		}
		int count = 0;
		for (i = 0; i < n_bit.size(); i++) {
			if (n_bit[i] != k_bit[i]) {
				if (k_bit[i] == 1 && n_bit[i] == 0) {
					count = -1;
					break;
				}
				else {
					count++;
				}
			}
		}
		return count;
	}
};
//2106 增量元素的最大差值
class Solution {
public:
	int maximumDifference(vector<int>& nums) {
		vector<int> result;
		for (int i = 0; i < nums.size() - 1; i++) {
			for (int j = i + 1; j < nums.size(); j++) {
				if (nums[j] > nums[i]) {
					result.push_back(nums[j] - nums[i]);
				}
			}
		}
		if (result.size() != 0) {
			auto max_it = max_element(result.begin(), result.end());
			return *max_it;
		}
		else
			return -1;
	}
};
//3701.计算交替和
class Solution {
public:
	int alternatingSum(vector<int>& nums) {
		int sum = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (i % 2 == 0) {
				sum = sum + nums[i];
			}
			else {
				sum = sum - nums[i];
			}
		}
		return sum;
	}
};
//1005.k次取反后最大化的数组和
class Solution {
public:
	int largestSumAfterKNegations(vector<int>& nums, int k) {
		sort(nums.begin(), nums.end());
		int negative_count = 0;
		int j = -1;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] <= 0) {
				negative_count++;
				j = i;
			}
		}
		int sum = 0;
		if (negative_count >= k) {
			int i = 0;
			while (i < nums.size()) {
				if (i < k) {
					sum = sum - nums[i];
				}
				else {
					sum += nums[i];
				}
				i++;
			}
			return sum;
		}
		else {
			int i = 0;
			int count = 0;
			if (negative_count != 0) {
				for (i = 0; i < j; i++) {
					sum = sum - nums[i];
					count++;
				}
				k -= count;
				if (j + 1 >= nums.size()) {
					int count1 = 0;
					while (count1 < k) {
						nums[j] = -1 * nums[j];
						count1++;
					}
					sum += nums[j];
					return sum;
				}
				else {
					if (abs(nums[j]) < abs(nums[j + 1])) {
						int count1 = 0;
						while (count1 < k) {
							nums[j] = -1 * nums[j];
							count1++;
						}
						sum += nums[j];
					}
					else {
						k--;
						sum -= nums[j];
						j++;
						int count1 = 0;
						while (count1 < k) {
							nums[j] = -1 * nums[j];
							count1++;
						}
						sum += nums[j];
					}
					j++;
					for (; j < nums.size(); j++) {
						sum += nums[j];
					}
					cout << sum << endl;
					return sum;
				}
			}
			else {
				while (count < k) {
					nums[0] = -1 * nums[i];
					count++;
				}
				sum = sum + nums[0];
				if (0 + 1 >= nums.size()) {
					return sum;
				}
				else {
					for (int f = 1; f < nums.size(); f++) {
						sum += nums[f];
					}
					return sum;
				}
			}
		}
	}
};
//3172.出现次数能被K整除的元素总和
class Solution {
public:
	int sumDivisibleByK(vector<int>& nums, int k) {
		map<int, int> array_count;
		for (int i = 0; i < nums.size(); i++) {
			auto it = array_count.find(nums[i]);
			if (it != array_count.end()) {
				it->second += 1;
			}
			else {
				array_count.insert(make_pair(nums[i], 1));
			}
		}
		int sum = 0;
		for (map<int, int> ::iterator it = array_count.begin(); it != array_count.end(); it++) {
			if (it->second % k == 0) {
				sum += (it->first) * (it->second);
			}
		}
		return sum;
	}
};
//3046.分割数组
class Solution {
public:
	bool isPossibleToSplit(vector<int>& nums) {
		map<int, int> array_find;
		for (int i = 0; i < nums.size(); i++) {
			auto it = array_find.find(nums[i]);
			if (it != array_find.end()) {
				it->second = it->second + 1;
			}
			else {
				array_find.insert(make_pair(nums[i], 1));
			}
		}
		for (auto it = array_find.begin(); it != array_find.end(); it++) {
			if (it->second > 2) {
				return false;
			}
		}
		return true;
	}
};
//LCP101.猜数字
class Solution {
public:
	int game(vector<int>& guess, vector<int>& answer) {
		int count = 0;
		for (int i = 0; i < guess.size(); i++) {
			if (guess[i] == answer[i]) {
				count++;
			}
		}
		return count;
	}
};
//LCR 库存管理II
class Solution {
public:
	int inventoryManagement(vector<int>& stock) {
		map<int, int> array_find;
		for (int i = 0; i < stock.size(); i++) {
			map<int, int> ::iterator it = array_find.find(stock[i]);
			if (it != array_find.end()) {
				it->second += 1;
			}
			else {
				array_find.insert(make_pair(stock[i], 1));
			}
		}
		for (map<int, int> ::iterator it = array_find.begin(); it != array_find.end(); it++) {
			if (it->second > stock.size() / 2) {
				cout << it->first << endl;
				return it->first;
			}
		}
		return 0;
	}
};
//747.至少是其他数字两倍的最大数
class Solution {
public:
	int dominantIndex(vector<int>& nums) {
		vector<int> ::iterator maxit = max_element(nums.begin(), nums.end());
		int number = *maxit;
		int flag = 0;
		for (int i = 0; i < nums.size(); i++) {
			if (number != nums[i] && nums[i] != 0) {
				if (number / nums[i] < 2) {
					return -1;
				}
			}
		}
		int i = 0;
		for (i = 0; i < nums.size(); i++) {
			if (nums[i] == number) {
				break;
			}
		}
		return i;
	}
};
//1078.BIGRAM分词
class Solution {
public:
	vector<string> findOcurrences(string text, string first, string second) {
		vector<string>  words;
		int j = 0;
		int i = 0;
		for (j = 0; j < text.size(); j++) {
			if (j == text.size() - 1) {
				string word(text.begin() + i, text.end());
				words.push_back(word);
			}
			if (text[j] == ' ') {
				string word(text.begin() + i, text.begin() + j);
				i = j + 1;
				words.push_back(word);
			}
		}
		vector<string> result;
		for (int i = 0; i < words.size() - 2; i++) {
			if (first == words[i]) {
				if (second == words[i + 1]) {
					result.push_back(words[i + 2]);
				}
			}
		}
		return result;
	}
};
//2180.统计各位数字之和为偶数的个数
class Solution {
public:
	int countEven(int num) {
		int i = 1;
		int count = 0;
		while (i <= num) {
			int sum = 0;
			int number = i;
			while (number) {
				sum = sum + (number % 10);
				number /= 10;
			}
			if (sum % 2 == 0) {
				count++;
			}
			i++;
		}
		return count;
	}
};
//3477.水果成蓝II
class Solution {
public:
	int numOfUnplacedFruits(vector<int>& fruits, vector<int>& baskets) {
		vector<int> contain_basket;
		contain_basket.resize(fruits.size(), 0);
		vector<int> put_up_fruits;
		put_up_fruits.resize(fruits.size(), 0);
		for (int i = 0; i < fruits.size(); i++) {
			for (int j = 0; j < baskets.size(); j++) {
				if (fruits[i] <= baskets[j] && contain_basket[j] == 0) {
					put_up_fruits[i] = 1;
					contain_basket[j] = 1;
					break;
				}
			}
		}
		int count = 0;
		for (int i = 0; i < put_up_fruits.size(); i++) {
			if (put_up_fruits[i] == 0) {
				count++;
			}
		}
		return count;
	}
};
//2784.检查数组是否完好
class Solution {
public:
	bool isGood(vector<int>& nums) {
		vector<int> ::iterator maxit = max_element(nums.begin(), nums.end());
		if (nums.size() == (*maxit + 1)) {
			map<int, int> array_find;
			for (int i = 0; i < nums.size(); i++) {
				auto it = array_find.find(nums[i]);
				if (it == array_find.end()) {
					array_find.insert(make_pair(nums[i], 1));
				}
				else {
					if (it->first == (*maxit))
						it->second += 1;
					else
						return false;
				}
			}
			int i = 1;
			while (i <= *maxit) {
				auto it = array_find.find(i);
				if (it == array_find.end()) {
					return false;
				}
				i++;
			}
			return true;
		}
		else {
			return false;
		}
	}
};
//179.检查总价格为目标值的两个商品
class Solution {
public:
	vector<int> twoSum(vector<int>& price, int target) {
		int i = 0;
		set<int> array;;
		for (int i = 0; i < price.size(); i++) {
			array.insert(price[i]);
		}
		vector<int> result;
		for (int i = 0; i < price.size(); i++) {
			auto it = array.find(target - price[i]);
			if (it != array.end()) {
				result.push_back(price[i]);
				result.push_back(target - price[i]);
				break;
			}
		}
		return result;
	}
};
//2540.最小公共值
class Solution {
public:
	int getCommon(vector<int>& nums1, vector<int>& nums2) {
		set<int> array;
		for (int i = 0; i < nums1.size(); i++) {
			array.insert(nums1[i]);
		}
		vector<int> result;
		for (int i = 0; i < nums2.size(); i++) {
			auto it = array.find(nums2[i]);
			if (it != array.end()) {
				result.push_back(nums2[i]);
			}
		}
		if (result.size() == 0) {
			return -1;
		}
		auto min_it = min_element(result.begin(), result.end());
		return *min_it;
	}
};
//LCR 024.反转链表
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
	ListNode* reverseList(ListNode* head) {
		ListNode* pre = NULL;
		ListNode* cur = head;
		while (cur != NULL) {
			ListNode* nextnode = cur->next;
			cur->next = pre;
			pre = cur;
			cur = nextnode;
		}
		return pre;
	}
};
//LCR 006.两数之和II-输入有序数组
class Solution {
public:
	vector<int> twoSum(vector<int>& numbers, int target) {
		multimap<int, int> array;
		for (int i = 0; i < numbers.size(); i++) {
			array.insert(make_pair(numbers[i], i));
		}
		vector<int> result;
		int i = 0;
		for (i = 0; i < numbers.size(); i++) {
			auto it = array.find(target - numbers[i]);
			if (it != array.end()) {
				result.push_back(i);
				if (it->second == i)
					result.push_back(i + 1);
				else
					result.push_back(it->second);
				break;
			}
		}
		return result;
	}
};
//LCR 120. 寻找两个文件副本
class Solution {
public:
	int findRepeatDocument(vector<int>& documents) {
		set<int> file_find;
		for (int i = 0; i < documents.size(); i++) {
			auto it = file_find.find(documents[i]);
			if (it == file_find.end()) {
				file_find.insert(documents[i]);
			}
			else {
				return documents[i];
			}
		}
		return 0;
	}
};
//LCR 024.反转链表
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
	ListNode* reverseList(ListNode* head) {
		ListNode* pre = NULL;
		ListNode* cur = head;
		while (cur != NULL) {
			ListNode* nextnode = cur->next;
			cur->next = pre;
			pre = cur;
			cur = nextnode;
		}
		return pre;
	}
};
//3731.找出缺失的元素
class Solution {
public:
	vector<int> findMissingElements(vector<int>& nums) {
		set<int> array;
		for (int i = 0; i < nums.size(); i++) {
			array.insert(nums[i]);
		}
		vector<int> result;
		auto min_it = min_element(nums.begin(), nums.end());
		auto max_it = max_element(nums.begin(), nums.end());
		int number = *min_it;
		while (number <= *max_it) {
			auto  it = array.find(number);
			if (it == array.end()) {
				result.push_back(number);
			}
			number++;
		}
		return result;
	}
};
//3591.检查元素的频次是否为素数
class Solution {
public:
	bool checkPrimeFrequency(vector<int>& nums) {
		map<int, int> prime_search;
		for (int i = 0; i < nums.size(); i++) {
			auto it = prime_search.find(nums[i]);
			if (it == prime_search.end()) {
				prime_search.insert(make_pair(nums[i], 1));
			}
			else {
				it->second += 1;
			}
		}
		for (auto it = prime_search.begin(); it != prime_search.end(); it++) {
			if (it->second >= 2) {
				int flag = 1;
				for (int i = 2; i < it->second; i++) {
					if (it->second % i == 0) {
						flag = 0;
						break;
					}
				}
				if (flag == 1) {
					return true;
				}
			}
		}
		return false;
	}
};
//3692.众数频率字符
class Solution {
public:
	string majorityFrequencyGroup(string s) {
		string little;
		vector<string> result;
		map<char, int> character;
		set<int> count_number;
		for (int i = 0; i < s.size(); i++) {
			auto it = character.find(s[i]);
			if (it != character.end()) {
				it->second += 1;
			}
			else {
				character.insert(make_pair(s[i], 1));
			}
		}
		for (auto it = character.begin(); it != character.end(); it++) {
			count_number.insert(it->second);
		}
		for (auto it = count_number.begin(); it != count_number.end(); it++) {
			int count = *it;

			string temp;
			for (auto its = character.begin(); its != character.end(); its++) {
				if (its->second == count) {
					temp.push_back(its->first);
				}
			}
			result.push_back(temp);
		}
		int max = 0;
		for (int i = 0; i < result.size(); i++) {
			if (result[i].size() > max) {
				max = result[i].size();
			}
		}
		for (int j = result.size() - 1; j >= 0; j--) {
			if (result[j].size() == max) {
				return result[j];
			}
		}
		return little;
	}
};
//1935.可以输入的最大单词数
class Solution {
public:
	int canBeTypedWords(string text, string brokenLetters) {
		vector<string> result;
		int i = 0;
		int j = 0;
		set<char> character;
		for (i = 0; i < brokenLetters.size(); i++) {
			character.insert(brokenLetters[i]);
		}
		i = 0;
		for (j = 0; j < text.size(); j++) {
			if (j == text.size() - 1) {
				string temp(text.begin() + i, text.end());
				result.push_back(temp);
				break;
			}
			if (text[j] == ' ') {
				string temp(text.begin() + i, text.begin() + j);
				i = j + 1;
				result.push_back(temp);
			}
		}
		int count = 0;
		for (i = 0; i < result.size(); i++) {
			int flag = 0;
			for (j = 0; j < result[i].size(); j++) {
				auto it = character.find(result[i][j]);
				if (it != character.end()) {
					flag = 1;
					break;
				}
			}
			if (flag == 0) {
				count++;
			}
		}
		return count;
	}
};
//2490.回环句
class Solution {
public:
	bool isCircularSentence(string sentence) {
		for (int i = 0; i < sentence.size(); i++) {
			if (i == sentence.size() - 1) {
				if (sentence[i] != sentence[0]) {
					return false;
				}
			}
			if (sentence[i] == ' ') {
				if (sentence[i + 1] != sentence[i - 1]) {
					return false;
				}
			}
		}
		return true;
	}
};
//2138.将字符串拆分成为若干长度为k的组
class Solution {
public:
	vector<string> divideString(string s, int k, char fill) {
		vector<string> result;
		int j = 0;
		int i = 0;
		for (i = 0; i < s.size(); i++) {
			if ((i + 1) % k == 0) {
				string  temp(s.begin() + j, s.begin() + i + 1);
				j = i + 1;
				result.push_back(temp);
			}
		}
		if (s.size() % k != 0) {
			int index = (s.size() / k) * k;
			int count = 0;
			string temp;
			for (; index < s.size(); i++) {
				temp.push_back(s[index]);
				index++;
				count++;
			}
			while (count < k) {
				temp.push_back(fill);
				count++;
			}
			result.push_back(temp);
		}
		return result;
	}
};
//884.两句话中不常见的单词
class Solution {
public:
	vector<string> uncommonFromSentences(string s1, string s2) {
		map<string, int> s1_word_count;
		map<string, int> s2_word_count;
		vector<string> only_one_s1_count;
		vector<string> only_one_s2_count;
		vector<string> result;
		int i = 0;
		for (int j = 0; j < s1.size(); j++) {
			if (j == s1.size() - 1) {
				string temp(s1.begin() + i, s1.end());
				auto it = s1_word_count.find(temp);
				if (it == s1_word_count.end()) {
					s1_word_count.insert(make_pair(temp, 1));
				}
				else {
					it->second += 1;
				}
				break;
			}
			if (s1[j] == ' ') {
				string temp(s1.begin() + i, s1.begin() + j);
				auto it = s1_word_count.find(temp);
				if (it == s1_word_count.end()) {
					s1_word_count.insert(make_pair(temp, 1));
				}
				else {
					it->second += 1;
				}
				i = j + 1;
			}
		}
		i = 0;
		for (int j = 0; j < s2.size(); j++) {
			if (j == s2.size() - 1) {
				string temp(s2.begin() + i, s2.end());
				cout << temp << endl;
				auto it = s2_word_count.find(temp);
				if (it == s2_word_count.end()) {
					s2_word_count.insert(make_pair(temp, 1));
				}
				else {
					it->second += 1;
				}
				break;
			}
			if (s2[j] == ' ') {
				string temp(s2.begin() + i, s2.begin() + j);
				cout << temp << endl;
				auto it = s2_word_count.find(temp);
				if (it == s2_word_count.end()) {
					s2_word_count.insert(make_pair(temp, 1));
				}
				else {
					it->second += 1;
				}
				i = j + 1;
			}
		}
		for (auto it = s1_word_count.begin(); it != s1_word_count.end(); it++) {
			if (it->second == 1) {
				only_one_s1_count.push_back(it->first);
			}
		}
		if (only_one_s1_count.size() != 0) {
			for (int j = 0; j < only_one_s1_count.size(); j++) {
				auto it = s2_word_count.find(only_one_s1_count[j]);
				if (it == s2_word_count.end()) {
					result.push_back(only_one_s1_count[j]);
				}
			}
		}
		for (auto it = s2_word_count.begin(); it != s2_word_count.end(); it++) {
			if (it->second == 1) {
				only_one_s2_count.push_back(it->first);
			}
		}
		if (only_one_s2_count.size() != 0) {
			for (int j = 0; j < only_one_s2_count.size(); j++) {
				auto it = s1_word_count.find(only_one_s2_count[j]);
				if (it == s1_word_count.end()) {
					result.push_back(only_one_s2_count[j]);
				}
			}
		}
		return result;
	}
};
//2402.出现最频繁的偶数元素
class Solution {
public:
	int mostFrequentEven(vector<int>& nums) {
		map<int, int> array;
		int max_count = 1;
		for (int i = 0; i < nums.size(); i++) {
			if (nums[i] % 2 == 0) {
				auto it = array.find(nums[i]);
				if (it == array.end()) {
					array.insert(make_pair(nums[i], 1));
				}
				else {
					it->second += 1;
					if (it->second > max_count) {
						max_count = it->second;
					}
				}
			}
		}
		if (array.size() == 0) {
			return -1;
		}
		else {
			for (auto it = array.begin(); it != array.end(); it++) {
				if (it->second == max_count) {
					return it->first;
				}
			}
			return 0;
		}
	}
};
//2451.差值数组不同的字符串
class Solution {
public:
	string oddString(vector<string>& words) {
		vector<vector<int>> mat_difference;
		mat_difference.resize(words.size());
		int n = words.size();
		for (int i = 0; i < n; i++) {
			mat_difference[i].resize(words[i].size() - 1);
		}
		for (int i = 0; i < words.size(); i++) {
			int f = 0;
			for (int j = 0; j < words[i].size() - 1; j++) {
				mat_difference[i][f] = (words[i][j + 1] - words[i][j]);
				f++;
			}
		}
		string result;
		for (int i = 1; i < mat_difference.size() - 1; i++) {
			if (mat_difference[i] != mat_difference[i - 1] && mat_difference[i] != mat_difference[i + 1]) {
				return words[i];
			}
		}
		if (mat_difference[0] != mat_difference[mat_difference.size() - 1] && mat_difference[0] != mat_difference[1]) {
			return words[0];
		}
		if (mat_difference[mat_difference.size() - 1] != mat_difference[0] && mat_difference[mat_difference.size() - 1] != mat_difference[mat_difference.size() - 2]) {
			return words[words.size() - 1];
		}
		return result;
	}
};
//1523.在区间范围内统计奇数数目
class Solution {
public:
	int countOdds(int low, int high) {
		int count = 0;
		while (low <= high) {
			if (low % 2 != 0) {
				count++;
			}
			low++;
		}
		return count;
	}
};
//1446.连续字符
class Solution {
public:
	int maxPower(string s) {
		vector<int> result;
		int i = 0;
		while (i < s.size() - 1) {
			if (s[i] == s[i + 1]) {
				int j = i;
				int count = 0;
				while (s[j] == s[i] && j < s.size()) {
					count++;
					j++;
				}
				result.push_back(count);
				i = j;
				continue;
			}
			i++;
		}
		if (result.size() == 0) {
			return 1;
		}
		vector<int> ::iterator it = max_element(result.begin(), result.end());
		return *it;
	}
};
//2248.多个数组的交集
class Solution {
public:
	vector<int> intersection(vector<vector<int>>& nums) {
		map<int, int> number_count;
		for (int i = 0; i < nums.size(); i++) {
			for (int j = 0; j < nums[i].size(); j++) {
				auto it = number_count.find(nums[i][j]);
				if (it == number_count.end()) {
					number_count.insert(make_pair(nums[i][j], 1));
				}
				else {
					it->second += 1;
				}
			}
		}
		vector<int> result;
		for (auto it = number_count.begin(); it != number_count.end(); it++) {
			if (it->second == nums.size()) {
				result.push_back(it->first);
			}
		}
		return result;
	}
};
//551.学生出勤记录I
class Solution {
public:
	bool checkRecord(string s) {
		int count = 0;
		int flag = 0;
		int i = 0;
		while (i < s.size()) {
			int L_count = 0;
			if (s[i] == 'A') {
				count++;
			}
			if (count >= 2) {
				flag = 1;
				break;
			}
			if (s[i] == 'L') {
				while (s[i] == 'L') {
					L_count++;
					i++;
				}
				if (L_count >= 3) {
					flag = 1;
					break;
				}
				continue;
			}
			i++;
		}
		if (flag == 1) {
			return  false;
		}
		else {
			return true;
		}
	}
};
//2873.有序三元组中的最大值
class Solution {
public:
	long long maximumTripletValue(vector<int>& nums) {
		vector<long long> result;
		vector<long long> res;
		for (int i = 0; i < nums.size(); i++) {
			res.push_back(nums[i]);
		}
		for (int i = 0; i < res.size() - 2; i++) {
			for (int j = i + 1; j < res.size() - 1; j++) {
				for (int k = j + 1; k < res.size(); k++) {
					long long temp = (res[i] - res[j]) * res[k];
					if (temp > 0) {
						result.push_back(temp);
					}
				}
			}
		}
		if (result.size() == 0) {
			return 0;
		}
		else {
			vector<long long> ::iterator it = max_element(result.begin(), result.end());
			return *it;
		}
	}
};
class Solution {
public:
	long long maximumTripletValue(vector<int>& nums) {
		vector<long long> result;
		vector<long long> res;
		for (int i = 0; i < nums.size(); i++) {
			res.push_back(nums[i]);
		}
		for (int i = 0; i < res.size() - 2; i++) {
			for (int j = i + 1; j < res.size() - 1; j++) {
				for (int k = j + 1; k < res.size(); k++) {
					long long temp = (res[i] - res[j]) * res[k];
					if (temp > 0) {
						result.push_back(temp);
					}
				}
			}
		}
		if (result.size() == 0) {
			return 0;
		}
		else {
			vector<long long> ::iterator it = max_element(result.begin(), result.end());
			return *it;
		}
	}
};
//1317.将整数转换为两个无零整数的和 
class Solution {
public:
	vector<int> getNoZeroIntegers(int n) {
		int i = 1;
		vector<int> result;
		while (i < n) {
			int flag = 0;
			int one_section = i;
			int other_section = n - i;
			while (one_section) {
				if (one_section % 10 == 0) {
					flag = 1;
					break;
				}
				one_section /= 10;
			}
			while (other_section) {
				if (other_section % 10 == 0) {
					flag = 1;
					break;
				}
				other_section /= 10;
			}
			if (flag == 0) {
				result.push_back(i);
				result.push_back(n - i);
				break;
			}
			i++;
		}
		return result;
	}
};
//2022.将一维数组转化为二维数组 
class Solution {
public:
	vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
		int count = m * n;
		vector<vector<int>> result;
		if (original.size() != count) {
			return result;
		}
		result.resize(m);
		for (int i = 0; i < m; i++) {
			result[i].resize(n);
		}
		int f = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				result[i][j] = original[f];
				f++;
			}
		}
		return result;
	}
};
//1331.数组序号转换
class Solution {
public:
	vector<int> arrayRankTransform(vector<int>& arr) {
		set<int> arr_num;
		map<int, int> array;
		for (int i = 0; i < arr.size(); i++) {
			arr_num.insert(arr[i]);
		}
		int k = 1;
		for (auto it = arr_num.begin(); it != arr_num.end(); it++) {
			int number = *it;
			array.insert(make_pair(number, k));
			k++;
		}
		vector<int> result;
		for (int i = 0; i < arr.size(); i++) {
			auto it = array.find(arr[i]);
			result.push_back(it->second);
		}
		return result;
	}
};
//1603.设计停车系统
class ParkingSystem {
public:
	vector<int> array;
	ParkingSystem(int big, int medium, int small) {
		array.push_back(big);
		array.push_back(medium);
		array.push_back(small);
	}

	bool addCar(int carType) {
		int index = carType - 1;
		if (array[index] == 0) {
			return false;
		}
		else {
			array[index] -= 1;
			return true;
		}
	}
};

/**
 * Your ParkingSystem object will be instantiated and called as such:
 * ParkingSystem* obj = new ParkingSystem(big, medium, small);
 * bool param_1 = obj->addCar(carType);
 */
 //3745.三元素表达式的最大值
class Solution {
public:
	int maximizeExpressionOfThree(vector<int>& nums) {
		sort(nums.begin(), nums.end());
		return nums[nums.size() - 1] + nums[nums.size() - 2] - nums[0];
	}
};
//1582.二进制矩阵中的特殊位置
class Solution {
public:
	int numSpecial(vector<vector<int>>& mat) {
		int count = 0;
		for (int i = 0; i < mat.size(); i++) {
			for (int j = 0; j < mat[i].size(); j++) {
				if (mat[i][j] == 1) {
					int flag = 0;
					int rowup = i - 1;
					int rowdown = i + 1;
					while (rowup >= 0) {
						if (mat[rowup][j] == 1) {
							flag = 1;
						}
						rowup--;
					}
					while (rowdown < mat.size()) {
						if (mat[rowdown][j] == 1) {
							flag = 1;
						}
						rowdown++;
					}
					int colleft = j - 1;
					int colright = j + 1;
					while (colleft >= 0) {
						if (mat[i][colleft] == 1) {
							flag = 1;
						}
						colleft--;
					}
					while (colright < mat[i].size()) {
						if (mat[i][colright] == 1) {
							flag = 1;
						}
						colright++;
					}
					if (flag == 0) {
						count++;
					}
				}
			}
		}
		return count;
	}
};
//3492.船上可以装载的最大集装箱数量
class Solution {
public:
	int maxContainers(int n, int w, int maxWeight) {
		int count = 0;
		int sum = 0;
		int flag = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (sum < maxWeight) {
					sum += w;
					count++;
				}
				else {
					flag = 1;
					break;
				}
			}
			if (flag == 1) {
				break;
			}
		}
		if (sum > maxWeight) {
			count--;
		}
		return count;
	}
};
//3541.找到频率最高的元音和辅音
class Solution {
public:
	int maxFreqSum(string s) {
		vector<int> result;
		result.resize(26, 0);
		int i = 0;
		for (int i = 0; i < s.size(); i++) {
			int index = (s[i] - 'a');
			result[index] = result[index] + 1;
		}
		vector<int> vowel;
		vowel.push_back(result['a' - 'a']);
		vowel.push_back(result['e' - 'a']);
		vowel.push_back(result['i' - 'a']);
		vowel.push_back(result['o' - 'a']);
		vowel.push_back(result['u' - 'a']);
		vector<int> result1;
		for (int i = 0; i < result.size(); i++) {
			if (i != ('a' - 'a') && i != ('e' - 'a') && i != ('i' - 'a') && i != ('o' - 'a') && i != ('u' - 'a')) {
				result1.push_back(result[i]);
			}
		}
		auto max_vowel = max_element(vowel.begin(), vowel.end());
		auto max_result = max_element(result1.begin(), result1.end());
		return (*max_vowel + *max_result);
	}
};